为人类设计的HTML解析宏。
项目描述
Requests-Html-Macros 是在已经非常出色的html解析库Requests-Html之上的小糖衣。
这个库旨在帮助使使用Requests-Html解析网络变得更加容易!创建可以在不同的网站/会话中重用的宏!你可以用requests-html手动做这件事,是的,可能非常简单,但我在开发这个库的一半路程时才意识到这一点,然后就像没关系,让我们无论如何推出它吧!
示例
from time import sleep
from requests_html_macro import Macro
from requests_html import HTMLSession
# Create a standard requests-html session
session = HTMLSession()
response = session.get('https://pythonlang.cn')
# Create a macro with the response
macro = Macro(response=response)
# Create a macro that uses the parse library to search through the html
@macro.search_pattern('Python is a {} language', first=True)
def foo(data):
print(data[0])
# Creates a macro that uses a css selector
@macro.css_selector('#about', first=True)
def foo1(data):
print(data.text)
@macro.xpath('//a', first=True)
def foo2(data):
print(data)
while True:
macro.parse()
sleep(30)
macro.response = session.get('https://pythonlang.cn')
安装
$ pip install requests-html-macro
项目详情
关闭
哈希值 用于 requests_html_macros-0.1.1-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c9628a7eb18876c9d385616cfd7936cedd99cc46e48aec4861a9ac49a2775578 |
|
MD5 | d52a265c6622cac5101721f775369a38 |
|
BLAKE2b-256 | 2cfab71ab1dd9cec15e0db4f68f77372a536ad0a4d1477590cf3b0bd904dbff8 |