Browse Source

add sleep

master
jyhl 4 years ago
parent
commit
0f24456f16
  1. 16
      demo.py

16
demo.py

@ -1,13 +1,14 @@
#!coding: utf-8
import os import os
import zipfile import zipfile
from selenium import webdriver from selenium import webdriver
PROXY_HOST = 'u1.5.tn.16yun.cn' # rotating proxy or host PROXY_HOST = 'u1.5.tn.16yun.cn' # rotating proxy or host
PROXY_PORT = 6441 # port PROXY_PORT = 6441 # port
PROXY_USER = '16ZJZYVL' # username PROXY_USER = '16ZJZYVL' # username
PROXY_PASS = '167813' # password PROXY_PASS = '112213' # password
manifest_json = """ manifest_json = """
{ {
@ -72,7 +73,7 @@ def get_chromedriver(use_proxy=False, user_agent=None):
# 如报错 chrome-extensions # 如报错 chrome-extensions
# chrome_options.add_argument("--disable-extensions") # chrome_options.add_argument("--disable-extensions")
# 防止被反爬 关闭webdriver flag # 防止被反爬 关闭 webdriver flag
# chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) # chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
if use_proxy: if use_proxy:
@ -89,10 +90,13 @@ def get_chromedriver(use_proxy=False, user_agent=None):
chrome_options=chrome_options) chrome_options=chrome_options)
return driver return driver
def main(): def main():
import time
driver = get_chromedriver(use_proxy=True) driver = get_chromedriver(use_proxy=True)
#driver.get('https://www.google.com/search?q=my+ip+address') driver.implicitly_wait(10) # seconds
driver.get('https://httpbin.org/ip') driver.get('https://httpbin.org/ip')
time.sleep(10)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save