Python 官方文档:入门教程 => 点击学习
requests-html async的使用示例代码:from requests_html import AsyncHTMLSession asession = AsyncHTMLSess
requests-html async的使用
示例代码:
from requests_html import AsyncHTMLSession
asession = AsyncHTMLSession()
ua = "Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWEBKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"
async def get_jd():
r = await asession.get('https://www.jd.com', headers={'user-agent': ua})
return r.html.xpath("//head/title/text()")[0]
async def get_taobao():
r = await asession.get('Https://www.taobao.com', headers={'user-agent': ua})
return r.html.xpath("//head/title/text()")[0]
async def get_amazon():
r = await asession.get('https://www.amazon.cn', headers={'user-agent': ua})
return r.html.xpath("//title/text()")[0]
async def get_suning():
r = await asession.get('https://www.suning.com', headers={'user-agent': ua})
return r.html.xpath("//title/text()")[0]
results = asession.run(get_jd, get_taobao, get_amazon, get_suning)
print(results)
返回结果;
['苏宁易购(Suning.com)-送货更准时、价格更超值、上新货更快', '亚马逊-网上购物商城:要网购, 就来Z.cn!', '淘宝网 - 淘!我喜欢', '京东(JD.COM)-正品低价、品质保障、配送及时、轻松购物!']
--结束END--
本文标题: requests-html async异步使用
本文链接: https://lsjlt.com/news/182278.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0