-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasync_demo.py
More file actions
38 lines (33 loc) · 1.37 KB
/
async_demo.py
File metadata and controls
38 lines (33 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
from requests_html2 import AsyncHTMLSession
from pprint import pprint
async def main():
async with AsyncHTMLSession(browser_launch_args={"headless": False}) as session:
resp = await session.get("https://www.smzdm.com/jingxuan/")
async with resp.async_render(reload=True) as page:
print(resp.html.xpath("/html/head/title").first().text)
print("=" * 80)
for _ in range(3):
await page.keyboard.press("PageDown")
await asyncio.sleep(1)
await resp.async_refresh_html()
top10 = resp.html.find(".feed-hot-card")[30:40]
for good in top10:
pprint(
{
"title": good.find(".feed-hot-title").select(
lambda e: e.text, first=True, default=""
),
"tips": good.find(".z-highlight").select(
lambda e: e.text, first=True, default=""
),
"img": good.find(".feed-hot-pic img").select(
lambda e: e.attrs.get("src", ""), first=True
),
"link": good.find("a").select(
lambda e: e.links.first(), first=True, default=""
),
}
)
if __name__ == "__main__":
asyncio.run(main())