python之selenium
一、安装
1、selenium
pip install selenium
pip install selenium
https://sites.google.com/a/chromium.org/chromedriver/downloads https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ https://github.com/mozilla/geckodriver/releases https://webkit.org/blog/6900/webdriver-support-in-safari-10/
下载好对应版本驱动,配置环境PATH(Windows),PATH加入驱动路径
from selenium import webdriver driver = webdriver.Chrome() driver.get("http://8.8.8.8/") for i in range(100): js="window.open('http://1.1.1.%s')" % str(i) driver.execute_script(js) #driver.quit()
from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get("http://www.python.org") assert "Python" in driver.title elem = driver.find_element_by_name("q") elem.clear() #清空自动填入的值,保证我们的输入 elem.send_keys("pycon") elem.send_keys(Keys.RETURN) assert "No results found." not in driver.page_source driver.close() #退出
1.id定位:find_element_by_id(self, id_) 2.name定位:find_element_by_name(self, name) 3.class定位:find_element_by_class_name(self, name) 4.tag定位:find_element_by_tag_name(self, name) 5.link定位:find_element_by_link_text(self, link_text) 6.partial_link定位find_element_by_partial_link_text(self, link_text) 7.xpath定位:find_element_by_xpath(self, xpath) 8.css定位:find_element_by_css_selector(self, css_selector) 9.id复数定位find_elements_by_id(self, id_) 10.name复数定位find_elements_by_name(self, name) 11.class复数定位find_elements_by_class_name(self, name) 12.tag复数定位find_elements_by_tag_name(self, name) 13.link复数定位find_elements_by_link_text(self, text) 14.partial_link复数定位find_elements_by_partial_link_text(self, link_text) 15.xpath复数定位find_elements_by_xpath(self, xpath) 16.css复数定位find_elements_by_css_selector(self, css_selector
refer:https://www.cnblogs.com/yoyoketang/p/6557421.html
https://selenium-python.readthedocs.io/locating-elements.html
from selenium.webdriver.support.select import Select
select_by_index # 通过索引定位
select_by_value # 通过value值定位
select_by_visible_text # 通过文本值定位
根据索引选择 Select(driver.find_element_by_name(“storeDeclare.cityLine”)).select_by_index(“3”)
根据value值选择 Select(driver.find_element_by_name(“storeDeclare.cityLine”)).select_by_value(“3线”)
根据文本值选择 Select(driver.find_element_by_name(“storeDeclare.cityLine”)).select_by_visible_text(“3线”)
refer:
#方式1,在中文前加入u # driver.find_element_by_class_name(“s_ipt”).send_keys(u’测试’) #方式2,使用decode()方法 str = ‘测试’ print str driver.find_element_by_class_name(“s_ipt”).send_keys(str.decode(‘utf-8’))
记得延时,不然有可能出错
driver.title #标题
driver.current_url #链接
element.send_keys("some text")
driver.find_element_by_id("submit").click()
driver.forward() driver.back()
cookie = {‘name’ : ‘foo’, ‘value’ : ‘bar’}
driver.add_cookie(cookie)
driver.get_cookies()
https://selenium-python.readthedocs.io/waits.html
https://selenium-python.readthedocs.io/api.html
https://seleniumhq.github.io/selenium/docs/api/py/api.html
Pandas高级教程之:GroupBy用法 目录 简介 分割数据 多index get_group dropn […]...
最近做一个有关二分类问题,我打算使用K-means算法实现baseline。 首先,我的数据文件形式是“.ar […]...
Python中最好用的命令行解析工具:argparse Python 做为一个脚本语言,可以很方便地写各种工具 […]...
train_test_split 数据切分 格式: X_train,X_test, y_train, y_te […]...
Python(发音:英[?pa?θ?n],美[?pa?θɑ:n]),是一种面向对象、直译式电脑编程语言,也是一 […]...
一、认识python python初识(一) python初识(二) python初识(三) 二、pyhton […]...
什么是对象和类 https://www.cnblogs.com/poloyy/p/15178423.html […]...
转 文章导读:以前自己一直没搞明白Python中的匿名函数,现在拿这个问题基本上搞明白了,拿自己的理解整成一篇文章,附带大量例子,让其更加好理解。在编程语言中,函数的应用:1. 代码块重复,这时候必须考虑用到函数,降低程序的冗余度2. 代...
欢迎加群交流(Spring Boot技术交流):490788638 Part V. Spring Boot A […]...
IOC Container 是laravel的一个核心内容,有了IOC Container在Laravel的强 […]...
继承 由于js不像java那样是真正面向对象的语言,js是基于对象的,它没有类的概念。 所以,要想实现继承,可 […]...
本文章来自https://www.cnblogs.com/iAmSoScArEd/p/10780242.htm […]...
/* ==================================================== […]...
JavaScript数据类型分为: 原始数据类型(7种) Number、String、Boolean、Null […]...
这个只能是试一下的方法,但不一定能成功,可以尝试如下几个方法: 1、登录远程桌面,然后以.登录SQL Se […]...
5.3.2 switch语句switch关键字的中文意思是开关、转换的意思,switch语句在条件语句中特别适 […]...
Powered By WordPress