码迷,mamicode.com
首页 > 编程语言 > 详细

python自动化打开网页

时间:2019-01-25 11:42:39      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:.exe   type   xpath   share   click   默认   comm   driver   argument   

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()

python自动化打开网页

标签:.exe   type   xpath   share   click   默认   comm   driver   argument   

原文地址:https://www.cnblogs.com/xiejianxiong/p/10317959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!