from requests_html import HTMLSession session =HTMLSession() response = session.get('https://www.cnblogs.com/pythonywy/') print(response.html.render())
执行的js代码css
语法:response.html.render(script='js代码字符串格式')
html
滑动滑块python
和sleep联用为多久滑动一次git
语法:response.html.render(scrolldown=页面向下滚动的次数)
github
加载页面失败的次数api
加载页面的等待时间(秒),防止超时(可选)浏览器
在页面初次渲染以后的等待时间cookie
页面加载时间上线session
若是为真,容许你用r.html.page访问页面async
若是为假,那么页面不会从浏览器中加载,而是从内存中加载
from requests_html import HTMLSession session =HTMLSession() response = session.get('https://www.cnblogs.com/pythonywy/') print(response.html.render(keep_page=true)) async def run(): #交互语句 await r.html.page.XXX try: session.loop.run_until_complete(run()) finally: session.close()
ms
点击
left
, right
, or middle
,点下去不抬起
抬起鼠标
等待
waitFor('选择器, 方法 或者 超时时间')
//
开头等待元素加载
waitForSelector('css选择器')
获取x,y坐标
mydic =await r.html.page.evaluate('''() =>{ var a = document.querySelector('#kw') #对象的css选择器 var b = a.getBoundingClientRect() return {'x':b.x,'y':b.y , 'width':b.width , 'height':b.height } }''')
执行js代码
evaluate('js代码字符串格式')
输入内容
type('css选择器',’内容‘,{’delay‘:100})
聚焦
focus('css选择器')
移动动到
hover('css选择器')
获取cookies
cookies()
设置页面大小
setViewport({'width': 1366, 'height': 768})
截图
screenshot({'path':保存本地路径,'clip':{'x':1,'y':1,'width':100,'height':100}})