水一篇文章,记录下近来忘记的小技巧

1.JS 三元表达式

前置条件 ? 结果一 : 结果二;

不管写成什么格式,都按照这样去看

2.xpath小语法

res= requests.get('url').text
html = etree.HTML(res)
# 取出包含文章主体
content= html.xpath('//*body[@id="aaa"]')[0]
text_one= etree.tostring(content, method='html')
text_two= HTMLParser().unescape(text_one.decode())
print(text_two)
text= response.xpath('//*span[@class="newText"]').xpath('string(.)')[0]

3.pyexecjs

import execjs

with open('tj.js','r',encoding='utf-8') as f:
    f_js = f.read()
f_js = execjs.compile(f_js.encode.decode('gbk','ignore'))
link_name = f_js.call('get_PWD','123456')
自有风云来时雨, 似有风霜沾蓑衣
原文地址:https://www.cnblogs.com/meipu/p/14081483.html