HTML为人类解析宏事物。
requests-html-macros的Python项目详细描述
requests html宏是一个已经很好的html解析库Requests-Html
这个库的目的是帮助解析web比用请求html更容易!创建可在不同网站/会话上重用的宏! 你能用请求html手工完成这个任务吗,是的,可能很简单,但是我只意识到liek开发这个库的一半,然后就好像搞砸了一样,让我们把它推出来!
示例
fromtimeimportsleepfromrequests_html_macroimportMacrofromrequests_htmlimportHTMLSession# Create a standard requests-html sessionsession=HTMLSession()response=session.get('http://python.org')# Create a macro with the responsemacro=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)deffoo(data):print(data[0])# Creates a macro that uses a css selector@macro.css_selector('#about',first=True)deffoo1(data):print(data.text)@macro.xpath('//a',first=True)deffoo2(data):print(data)whileTrue:macro.parse()sleep(30)macro.response=session.get('http://python.org')
安装
$ pip install requests-html-macro