forked from Boris-code/feapder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_playwright.py
More file actions
43 lines (32 loc) · 1.06 KB
/
Copy pathtest_playwright.py
File metadata and controls
43 lines (32 loc) · 1.06 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
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on 2022/9/15 8:47 PM
---------
@summary:
---------
@author: Boris
@email: boris_liu@foxmail.com
"""
import time
from playwright.sync_api import Page
import feapder
from feapder.utils.webdriver import PlaywrightDriver
class TestPlaywright(feapder.AirSpider):
__custom_setting__ = dict(
RENDER_DOWNLOADER="feapder.network.downloader.PlaywrightDownloader",
)
def start_requests(self):
yield feapder.Request("https://www.baidu.com", render=True)
def parse(self, reqeust, response):
driver: PlaywrightDriver = response.driver
page: Page = driver.page
page.type("#kw", "feapder")
page.click("#su")
page.wait_for_load_state("networkidle")
time.sleep(1)
html = page.content()
response.text = html # 使response加载最新的页面
for data_container in response.xpath("//div[@class='c-container']"):
print(data_container.xpath("string(.//h3)").extract_first())
if __name__ == "__main__":
TestPlaywright(thread_count=1).run()