此博客仅用于记录个人学习进度,学识浅薄,若有错误观点欢迎评论区指出。欢迎各位前来交流。(部分材料来源网络,若有侵权,立即删除)
本人博客所有文章纯属学习之用,不涉及商业利益。不合适引用,自当删除!
若被用于非法行为,与我本人无关
pip install selenium
from selenium import webdriver print(help(webdriver))
from selenium import webdriver driver = webdriver.Chrome() url='http://www.baidu.com' driver.get(url)
from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Chrome() url='https://blog.csdn.net/Q_U_A_R_T_E_R?spm=1000.2115.3001.5343' driver.get(url) html = driver.page_source soup = BeautifulSoup(html,'lxml') print(soup)
from selenium import webdriver driver = webdriver.Chrome() url='http://www.baidu.com' driver.get(url) driver.find_element_by_xpath('//*[@id="kw"]').clear()#清空搜索框 driver.find_element_by_xpath('//*[@id="kw"]').send_keys("你好")#输入搜索内容
find_element_by_id()
find_element_by_name()
find_element_by_class_name()
find_element_by_tag_name()
find_element_by_link_text()
find_element_by_partial_link_text()
find_element_by_xpath()
find_element_by_css_selector()
html = driver.page_source
from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Chrome() url='https://blog.csdn.net/Q_U_A_R_T_E_R?spm=1000.2115.3001.5343' driver.get(url) html = driver.page_source
from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Chrome() url='https://blog.csdn.net/' driver.get(url) input() time.sleep(3) cookie=driver.get_cookies() print(cookie) cookies = {cookie['name']:cookie['value'] for cookie in cookie} print(cookies)
cookie_dict = { 'domain': '.damai.cn', 'name': cookie.get('name'), 'value': cookie.get('value'), "expires": '', 'path': '/', 'httpOnly': False, 'HostOnly': False, 'Secure': False } driver.add_cookie(cookie_dict) driver.refresh()
from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Chrome() url='https://blog.csdn.net/' driver.get(url) URL=driver.current_url print(URL)
from selenium import webdriver driver = webdriver.Chrome() url='http://www.baidu.com' driver.get(url) driver.find_element_by_xpath('//*[@id="kw"]').clear()#清空搜索框 driver.find_element_by_xpath('//*[@id="kw"]').send_keys("你好,世界")#输入搜索内容 driver.find_element_by_xpath('//*[@id="su"]').click()#点击搜索键
end
selenium内容比较多可能会多写几篇博客学习