跳转到主要内容

为人类设计的HTML解析宏。

项目描述

https://travis-ci.org/erinxocon/requests-html-macros.svg?branch=master https://img.shields.io/pypi/v/requests-html-macros.svg?maxAge=2592000 https://img.shields.io/pypi/l/requests-html-macros.svg?maxAge=2592000

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.tar.gz (4.0 kB 查看哈希)

上传时间:

构建分布

requests_html_macros-0.1.1-py2.py3-none-any.whl (4.8 kB 查看哈希)

上传于 Python 2 Python 3

由以下支持