-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathraw_gas_info_async.py
More file actions
40 lines (35 loc) · 1.41 KB
/
raw_gas_info_async.py
File metadata and controls
40 lines (35 loc) · 1.41 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
import asyncio
from playwright.async_api import async_playwright
from seleniumbase import cdp_driver
async def main():
driver = await cdp_driver.start_async()
endpoint_url = driver.get_endpoint_url()
tab = await driver.get("about:blank")
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(endpoint_url)
context = browser.contexts[0]
page = context.pages[0]
url = (
"https://www.gassaferegister.co.uk/gas-safety"
"/gas-safety-certificates-records/building-regulations-certificate"
"/order-replacement-building-regulations-certificate/"
)
await page.goto(url)
await tab.sleep(0.6)
await tab.solve_captcha()
await page.wait_for_selector("#SearchTerm")
await tab.sleep(1.4)
allow_cookies = 'button:contains("Allow all cookies")'
await tab.click_if_visible(allow_cookies, timeout=2)
await tab.sleep(1)
await page.fill("#SearchTerm", "Hydrogen")
await page.click("button.search-button")
await tab.sleep(3)
results = await tab.query_selector_all("div.search-result")
for result in results:
print(result.text.replace(" " * 12, " ").strip() + "\n")
await tab.scroll_down(50)
await tab.sleep(1)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())