Форум сайта python.su
Имею следующий кусок кода:
import time import requests from fake_useragent import UserAgent from lxml import html from selenium import webdriver from selenium.webdriver.chrome.options import Options url_whoer = 'https://whoer.net/ru' PROXY = 'http://96.80.89.69:8080' def proxy_checker_requests(): proxies = { 'http': PROXY } response = requests.get(url_whoer, proxies=proxies) dom = html.fromstring(response.text) try: proxy_status = dom.xpath('string(//span[@class="cont proxy-status-message"])').strip() print('--- REQUESTS ---') if proxy_status == 'Нет': print('{} - Прокси "Нет" - True'.format(PROXY)) else: print('{} - Прокси "Да" - False'.format(PROXY)) except Exception as e: print('ERROR: ', e) def proxy_checker_selenium(): ua = UserAgent() options = Options() # options.add_argument('--headless') options.add_argument('--user-agent={}'.format(ua.random)) options.add_argument('--proxy-server=%s' % PROXY) driver = webdriver.Chrome(chrome_options=options, executable_path="C:\chromedriver.exe") driver.get(url_whoer) try: proxy_status = driver.find_element_by_xpath('//span[@class="cont proxy-status-message"]').text print('--- SELENIUM ---') if proxy_status == 'Нет': print('{} - Прокси "Нет" - True'.format(PROXY)) else: print('{} - Прокси "Да" - False'.format(PROXY)) except Exception as e: print('ERROR: ', e) if __name__ == '__main__': proxy_checker_requests() time.sleep(3) proxy_checker_selenium()
Отредактировано hubble (Март 9, 2018 21:41:33)
Офлайн