1from urllib.parse import urljoin
2from apify import Actor
3from seleniumwire import webdriver as sdriver
4from selenium import webdriver
5from selenium.webdriver.chrome.options import Options as ChromeOptions
6from selenium.webdriver.common.by import By
7from selenium.webdriver.common.keys import Keys
8from selenium.webdriver.support import expected_conditions as EC
9from selenium.webdriver.support.ui import WebDriverWait
10import asyncio
11
12
13
14
15
16
17
18def wiredriver(PROXY):
19 seleniumwire_options = {
20 'proxy': {'http': PROXY,'verify_ssl': False,},'start-maximized': True,'headless': True,}
21 chrome_options = ChromeOptions()
22
23
24 mobile_emulation = {
25 "deviceMetrics": { "width": 1920, "height": 1080, "pixelRatio": 3.0 },
26 "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"}
27
28
29
30
31
32
33
34 chrome_options.add_argument('--no-sandbox')
35
36
37 driver = sdriver.Chrome(options=chrome_options, seleniumwire_options=seleniumwire_options)
38
39 return driver
40
41url_adsite = 'https://a000.ex16.repl.co/'
42
43
44async def main():
45 async with Actor:
46
47
48 proxy_configuration = await Actor.create_proxy_configuration(groups=['RESIDENTIAL'])
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 proxy1 = await proxy_configuration.new_url()
68 driver = wiredriver(proxy1)
69
70
71
72 driver.maximize_window()
73
74 run = True
75 while run:
76 try:
77 driver.get(url_adsite)
78 except:
79 print('url failed')
80
81
82
83
84 x = '/html/body/hthtmlml/h1[6]/div[2]/div[2]/div[1]/div'
85
86 driver.execute_script("window.scrollTo(0, 1080);")
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 Actor.log.info(f'Scraping {url_adsite} ...')
102
103
104
105
106
107
108
109