首页 > 编程语言 >【Python】使用requests_html解析HTML页面

【Python】使用requests_html解析HTML页面

时间:2022-08-19 14:11:35浏览次数:68  
标签:Python html 537.36 HTML https download requests com

1、官网

https://pypi.org/project/requests-html/

 

2、github

https://github.com/kennethreitz/requests-html

 

3、安装

pip install requests-html

 

 

4、使用HTMLSession

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36'}
download_url = 'https://registry.npmmirror.com/binary.html?path=chromedriver/'

from requests_html import HTMLSession

session = HTMLSession()

r = session.get(download_url)

r.html.render()  # this call executes the js in the page

print(r.html.find('html'))

 

5、使用AsyncHTMLSession

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36'}
download_url = 'https://registry.npmmirror.com/binary.html?path=chromedriver/'


from requests_html import AsyncHTMLSession

asession = AsyncHTMLSession()


async def get_webdriver():
    r = await asession.get(download_url)
    await r.html.arender()
    return r


results = asession.run(get_webdriver)
print(results)

 

 

 

参考链接:

https://www.cnblogs.com/angelyan/p/13913926.html

https://www.cnblogs.com/Sadusky/p/12887215.html

https://www.cnblogs.com/pythonywy/p/11694967.html

https://baijiahao.baidu.com/s?id=1701142223076604985&wfr=spider&for=pc

标签:Python,html,537.36,HTML,https,download,requests,com
From: https://www.cnblogs.com/fireblackman/p/16601779.html

相关文章

  • Python数据类型
    在Python3中,有6种标准的数据类型:Number(数字)、String(字符串)、List(列表)、Tuple(元组)、Set(集合)、Dictionary(字典),见表2-2。  Python3中支持3种不同的数值类型,包括int(整型......
  • Pybinder-python与c++的调用
    目录Areallygoodproject.ExportCpptopythonunerLinuxplatformAreallygoodproject.https://github.com/pybind/pybind11https://github.com/pybind/pyb......
  • 解决python import找不到自定义包的问题
    文件结构如下├──A│├──a.py│├──__init__.py│└──b.py├──B│├──c.py│├──__init__.py│└──d.py想在c.py调用......
  • Python的数据类型-可变类型和不可变类型
    Python数据类型-可变类型和不可变类型的区别python数据类型有6类:不可变数据类型:数字、字符串、元组可变数据类型:列表、集合、字典可变数据类型和不可变数据类型的区别......
  • Python小整数池-小数据池-驻留机制-is和==区别
    Python小整数池-小数据池-驻留机制-is和==区别1.is和==的区别相同点:都用来比较两个对象是否一样不同点:is用来比较是否是同一个对象,即对象的物理地址是否相同(id(......
  • 10个常用的损失函数解释以及Python代码实现
    什么是损失函数?损失函数是一种衡量模型与数据吻合程度的算法。损失函数测量实际测量值和预测值之间差距的一种方式。损失函数的值越高预测就越错误,损失函数值越低则预测越......
  • Python-05输入输出
    Python输入语句:     在Python3.x中raw_input()和input()进行了整合,去除raw_input(),仅仅保留了Input()函数,其接收任意输入,将所有输入默认为字符串处理,并返回字符......
  • Python - PyPDF2模块的简单使用
    1.简介PyPDF的前身是PyPDF包在2005年发布,该包的最后一个版本发布于2010年,后来大约经过一年左右,名为Phasit的公司赞助PyPDF的一个分支后来命名为PyPDF2,两个版本功能都基本......
  • PYTHON实现倒三角打印
    目录需求数据展示最终结果实现效果代码原始版本1代码效率需求数据展示以空格分隔的990个数据最终结果实现效果代码发现我自己是真的喜欢暴力求解,当然昨天是因为有......
  • vue pdf导出 html2canvas+jspdf
    第一个.将页面html转换成图片npminstall--savehtml2canvas第二个.将图片生成pdfnpminstalljspdf--save官方文档  http://html2canvas.hertzen.com/ //导......