如何修复硒铬中的ip旋转而不关闭

时间:2019-06-22 07:09:04

标签: python

我正在使用Windows 10和python3。我的问题是使用硒铬驱动程序。我已经写了一些代码,但是出错了。当我被禁止时,我需要轮换代理。请帮助您解决我的代码

# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep
import random
# import urls as urls

urls=[


'https://angel.co/_tom_c_',
'https://angel.co/2lr',
'https://angel.co/aamerbdullah10',
'https://angel.co/aaronbatalion',
'https://angel.co/aaron-bertinetti',
'https://angel.co/aaron-schumm-1',
'https://angel.co/aarrieta',
'https://angel.co/abenmeir-me-com',
'https://angel.co/abhas2002',
'https://angel.co/abrams',
'https://angel.co/adam-gerstein',
'https://angel.co/adam-rogas',
'https://angel.co/adam-rothenberg',
'https://angel.co/adaugelli',
'https://angel.co/adil-wali',]




out = r'E:\\out_html\\'

PROXY = [

'196.202.153.67:3128',
'177.125.243.12:3128',
'43.245.216.190:8080',
'45.221.77.82:8080',
'202.62.12.50:80',

]

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f'--proxy-server={random.choice(PROXY)}')

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.delete_all_cookies()

x = 0
for link in urls.urls:
    driver.get(link)
    while "Sorry for the interruption..." in driver.page_source or 'No internet' in driver.page_source or "Please complete the security check to access" in driver.page_source:
        driver.delete_all_cookies()

        if "Sorry for the interruption..." in driver.page_source or 'No internet' in driver.page_source or "Please complete the security check to access" in driver.page_source:

            if "Sorry for the interruption..." in driver.page_source:
                print('\n')
                print('Sorry for the interruption')
            if 'No internet' in driver.page_source:
                print('\n')
                print('Sorry for No internet')
            if "Please complete the security check to access" in driver.page_source:
                print('\n')
                print('Please complete the security check to access')
            # sleep(120)
            # driver.execute_script("window.stop();")
            # rr = input('type r and hit enter to start again ! : ')
            # if rr =='r' or '' in rr:

            #     driver.refresh()

            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument(f'--proxy-server={random.choice(PROXY)}')

            driver = webdriver.Chrome(chrome_options=chrome_options)
            driver.delete_all_cookies()
            driver.get(link)



    x+=1
    nn = link.split('/')[-1]
    with open(out+f'{nn} {x}.html', 'wb') as f:
        f.write(driver.page_source.encode("utf-8"))

    print('\n')
    print(f'{nn} {x}.html')
    driver.delete_all_cookies()
    driver.quit()


print('done click to end')

input()

我希望这会循环所有网址并随机获取代理列表 <------------------------------------------------- ------------------------>

0 个答案:

没有答案