-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathproxy.py
More file actions
44 lines (31 loc) · 1.11 KB
/
Copy pathproxy.py
File metadata and controls
44 lines (31 loc) · 1.11 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
import sys
from lxml.html import fromstring
from selenium import webdriver
def get_proxies():
url = 'https://www.us-proxy.org'
driver = webdriver.Chrome()
driver.get(url)
driver.set_window_size(1920, 1080) # Must be re-sized to display form
filter_field = driver.find_element_by_xpath("//input[@type='search']")
filter_field.send_keys('yes')
proxies = []
for page in range(5):
parser = fromstring(driver.page_source)
for i in parser.xpath('//tbody/tr')[:20]:
try:
proxy = ":".join([i.xpath('.//td[1]/text()')[0], i.xpath('.//td[2]/text()')[0]])
proxies.append(proxy)
except IndexError:
return list(set(proxies))
driver.find_element_by_id('proxylisttable_paginate').click()
return list(set(proxies))
PROXIES = get_proxies()
def get_next_proxy():
if len(PROXIES) == 0:
print('No proxies remaining')
sys.exit(1)
else:
next_proxy = PROXIES[0]
print('The following proxy was requested: {}'.format(next_proxy))
del(PROXIES[0])
return next_proxy