python爬虫--selenium的基础使用,cookie,select,行为链
代码
代码
from selenium
import webdriver
from selenium
.webdriver
.support
.ui
import Select
from selenium
.webdriver
.common
.by
import By
from selenium
.webdriver
.common
.action_chains
import ActionChains
driver
= webdriver
.Chrome
(
executable_path
=r
"C:\Users\86199\AppData\Local\Google\Chrome\Application\chromedriver.exe")
driver
.get
("http://www.baidu.com")
driver
.find_element
(By
.ID
,'kw')
cookies
=driver
.get_cookies
()
for cookie
in cookies
:
print(cookie
)
driver
.add_cookie
({"name":"dasudyaui","value":"12344"})
print('获取指定的cookie的值',driver
.get_cookie
("dasudyaui"))
driver
.delete_cookie
("hushaojie")
print('删除指定的cookie的值后获取',driver
.get_cookie
("dasudyaui"))
driver
.delete_all_cookies
()
if driver
.get_cookies
() is not None:
print('数据不为空',driver
.get_cookies
())
for cookie
in driver
.get_cookies
():
print(cookie
)
else:
print('数据为空')
select
= Select
(driver
.find_element_by_id
('kd'))
select
.select_by_index
()
select
.select_by_value
()
select
.deselect_by_visible_text
()
action
=ActionChains
(driver
=driver
)
inputtag
=driver
.find_element_by_id
("kw")
buttontag
=driver
.find_element
(By
.ID
,'su')
action
.move_to_element
(inputtag
)
inputtag
.send_keys
('12142141234231412341')
action
.move_to_element
(buttontag
)
buttontag
.click
()
转载请注明原文地址:https://blackberry.8miu.com/read-27920.html