requests-html的js执行功能简单使用


#!/usr/bin/env python
# encoding: utf-8  
import asyncio
from requests_html import HTMLSession
import time
script = """
    () => {
        return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight,
            deviceScaleFactor: window.devicePixelRatio,
        }
    }
"""
geturl="""
  () =>
   {
 return{ url:document.location.href}
   }
"""
loginjs="""
  () =>
   {
    var email=document.getElementById("email")
    email.value="用户名"
    var pwd=document.getElementById("pass")
    pwd.value="密码"
    var submit=document.getElementById("loginbutton")
    submit.click()
   }
"""
#运行js
session=HTMLSession()
r=session.get("https://www.facebook.com/login.php?login_attempt=1")
#开始调用pyppeteer
dom=r.html
#page1=dom.render()#相当于await page.evaluate

#page=dom.render(script=script)#相当于await page.evaluate

# print(dir(dom)) #获取dom对象所有的属性和方法
# print(dom.__dict__) #获取dom对象所有的属性和值,字典形式
# print(dom.links) #获取所有相对连接
# print(dom.absolute_links) #获取所有连接的完整路径
#dom.session就相当于requests模块的response了
#print(dom.render(script=geturl))
print(dom.render(script=loginjs))
time.sleep(5)
print(dom.session)

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM