python自動化打開網頁


from selenium.webdriver.firefox.options import Options as FOptions
from selenium.webdriver.chrome.options import Options as Foptions
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains


from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

#firefox設置代理
profile = FirefoxProfile()
# 激活手動代理配置(對應着在 profile(配置文件)中設置首選項)
profile.set_preference("network.proxy.type", 1)
# ip及其端口號配置為 http 協議代理
profile.set_preference("network.proxy.http", "127.0.0.1")
profile.set_preference("network.proxy.http_port", 8080)

# 所有協議共用一種 ip 及端口,如果單獨配置,不必設置該項,因為其默認為 False
profile.set_preference("network.proxy.share_proxy_settings", True)

#chrome設置代理
# options = FOptions()


options = FOptions()
chrome_options = webdriver.FirefoxOptions()
chrome_options.add_argument('--proxy-server=http://127.0.0.1:8080')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('disable-infobars')
browser = webdriver.Firefox(executable_path="D:/geckodriver.exe",firefox_profile=profile)

browser.maximize_window()
browser.get('https://account.dianping.com/login?redir=http%3A%2F%2Fwww.dianping.com%2F')

button = browser.find_element_by_xpath('/html/body/div/div[2]/div[5]/span')
button.click()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM