-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaywrightAsync.py
More file actions
39 lines (26 loc) · 972 Bytes
/
Copy pathPlaywrightAsync.py
File metadata and controls
39 lines (26 loc) · 972 Bytes
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
import asyncio
import time
from playwright.async_api import async_playwright
async def run_browser(instance_number, playwright):
datacenter_proxy = {
'server': 'http://156.228.86.29:3128',
}
residential_proxy = {
'server': 'http://rp.scrapegw.com:6060',
'username': 'proxy_username',
'password': 'proxy_password'
}
browser = await playwright.chromium.launch(proxy=residential_proxy, headless=False)
context = await browser.new_context()
page = await context.new_page()
await page.goto("https://httpbin.org/ip")
time.sleep(3)
content = await page.content()
print(f"Browser {instance_number} IP information: {content}")
await browser.close()
async def main():
async with async_playwright() as playwright:
# Create tasks for each browser instance
tasks = [run_browser(i, playwright) for i in range(1, 4)]
await asyncio.gather(*tasks)
asyncio.run(main())