~玉米糊~
慢慢来,也会很快。 非宁静无以志学,学什么都一样,慢慢打基础,找规律、认真、坚持,其余的交给时间。
随笔 - 117,  文章 - 17,  评论 - 1,  阅读 - 82072

参数:--headless

用途:启用无界面模式

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

无界面模式示例:

复制代码
 1 from selenium import webdriver
 2 chrome_options = webdriver.ChromeOptions()
 3 #启用无界面模式
 4 chrome_options.add_argument('--headless')
 5 driver = webdriver.Chrome(chrome_options=chrome_options)
 6 url = "file:///E:/log/index.html"
 7 driver.get(url)
 8 keys = []
 9 for i in range(1,13):
10     #使用format代替%s
11     key = driver.find_element_by_xpath('//*[@id="statisticsTable"]/thead/tr/th[{id}]/div'.format(id = i)).text
12     keys.append(key)
13 
14 valuestr = driver.find_element_by_xpath('//*[@id="statisticsTable"]/tbody[2]/tr').text
15 values = valuestr.split(" ")
16 #字典推导式,in后面必须加元祖或zip的迭代器等
17 
18 dict = {key: value for key,value in zip(keys, values)}
19 print(dict)
20 
21 driver.close()
复制代码

参考:

https://www.cnblogs.com/carlvine/articles/9151837.html

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

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

 

posted on   yuminhu  阅读(399)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示