【Python~分享】selenium库实现自动打开谷歌浏览器,搜索腾讯视频,登录腾讯视频

from selenium import webdriver
from selenium.webdriver import ActionChains
import time
browser = webdriver.Chrome()
browser.maximize_window()

browser.get("https://www.baidu.com/")
tx=browser.find_element_by_id("kw")
tx.send_keys("腾讯视频")
search=browser.find_element_by_id("su")
search.click()
time.sleep(1)

txsp=browser.find_element_by_xpath("//div[@id='1']/h3[@class='t']")
txsp.click()
time.sleep(1)

browser.get('https://v.qq.com/')
time.sleep(1)

instant_login=browser.find_element_by_xpath("//div[@id='mod_head_user']/a")
instant_login.click()
time.sleep(1)

change=browser.find_element_by_xpath("//div[@class='login_btns']/a[1]")
change.click()
time.sleep(1)

browser.switch_to.frame("_login_frame_quick_")#跳转iframe

login=browser.find_element_by_xpath("//div[@id='bottom_qlogin']/a[1]")
login.click()
time.sleep(1)
input=browser.find_element_by_id("u")
input.send_keys("XXXXX")#填写账号
password=browser.find_element_by_id("p")
password.send_keys("XXXXX")#填写密码
button=browser.find_element_by_id("login_button")
button.click()
time.sleep(1)

frame=browser.find_element_by_xpath("//div[@id='newVcodeIframe']/iframe")
browser.switch_to.frame(frame)
hua=browser.find_element_by_id("tcaptcha_drag_button")
action = ActionChains(browser)# 实例化一个action对象
action.click_and_hold(hua).perform()# perform()用来执行ActionChains中存储的行为
action.reset_actions()
action.move_by_offset(183, 0).perform()# 移动滑块
action.reset_actions()
action.move_to_element(hua)

browser.switch_to.parent_frame()

browser.switch_to.parent_frame()#返回父页面

time.sleep(1)
browser.execute_script('window.scrollBy(0,2580)')

bianfu=browser.find_element_by_xpath("//div[@id='custommovie']/div[2]//li[1]")
bianfu.click()

now_url=browser.current_url
print(now_url)
print(browser.get_cookies())
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值