获取网页中JavaScript渲染后的信息
发表在Python图书答疑
2021-04-27
悬赏:1 学分
《Python网络爬虫从入门到实践》第6章 高级网络请求模块 107页-110页
是否精华
是
否
版块置顶:
是
否
from requests_html import HTMLSession,UserAgent #导入HTMLSession类
session = HTMLSession() #创建HTML会话对象
ua =UserAgent().random #创建随机请求头
#发送网络请求
r =session.get('https://movie.douban.com/tag/#/?sort=U&range=0,10&tags=%E7%94%B5%E5%BD%B1,2020',headers = {'user-agent': ua})
r.encoding = 'gb2312'
if r.status_code == 200:
r.html.render()
输出报错:
RuntimeError: Cannot use HTMLSession within an existing event loop. Use AsyncHTMLSession instead.
购物车
发表新帖
立即签到







