Chrome启动参数(无界面等)

参数:--headless

用途:启用无界面模式

参数:--disable-popup-blocking
用途:禁用弹出拦截

无界面模式示例:

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
#启用无界面模式
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=chrome_options)
url = "file:///E:/log/index.html"
driver.get(url)
keys = []
for i in range(1,13):
    #使用format代替%s
    key = driver.find_element_by_xpath('//*[@id="statisticsTable"]/thead/tr/th[{id}]/div'.format(id = i)).text
    keys.append(key)

valuestr = driver.find_element_by_xpath('//*[@id="statisticsTable"]/tbody[2]/tr').text
values = valuestr.split(" ")
#字典推导式,in后面必须加元祖或zip的迭代器等

dict = {key: value for key,value in zip(keys, values)}
print(dict)

driver.close()

参考:https://www.cnblogs.com/roystime/p/7117515.html     (无界面浏览)

   https://www.cnblogs.com/xiaoxiao-niao/p/7765627.html     (Chrome启动参数)

      https://mp.weixin.qq.com/s/038NwipSwT5GgIykm09m7Q  (format代替%s等)   

def open(browser="Chrome",url="http://10.138.61.61/PostLoan/BILLDUN/DUNLETTERGENERATION.ASPX"):
    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
    option.add_argument('--user-data-dir=C:\\Users\FF\AppData\Local\Google\Chrome\\User Data') 
#设置成用户自己的数据目录 driver = eval("webdriver.%s()" %browser) driver.get(url) driver.find_element_by_id("txtUserName").send_keys("fanyw") driver.find_element_by_id("txtPwd").send_keys("1234567b") sleep(1) # driver.find_element_by_id("btnLogin").click() print("I was at the chrome %s" %ctime()) def startFirefoxWithSpecificLocation(): """启动安装在 非 默认位置的Firefox浏览器,并自动转到 百度 首页""" binary = FirefoxBinary('D:\Program Files\Mozilla Firefox\\firefox.exe') driver = webdriver.Firefox(firefox_binary=binary) driver.get("http://10.138.61.61/PostLoan/BILLDUN/DUNLETTERGENERATION.ASPX")

 

转载于:https://www.cnblogs.com/carlvine/articles/9151837.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值