Python爬虫selenium模拟登陆QQ空间

# Author: Sooele

#后去豆瓣中更多电影详情数据
from selenium import webdriver
from time import sleep
#谷歌无头(页面)浏览器
# from selenium.webdriver.chrome.options import Options
# chrome_options = Options()
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
url = 'https://qzone.qq.com/'
bro = webdriver.Chrome(executable_path=r'G:\软件全家桶\Pycharm\Pys15\day137爬虫\chromedriver.exe')
# bro = webdriver.Chrome(executable_path=r'G:\软件全家桶\Pycharm\Pys15\day137爬虫\chromedriver.exe',chrome_options=chrome_options)

bro.get(url=url)
sleep(2)
#定位刀一个具体的iframe
bro.switch_to.frame('login_frame')
bro.find_element_by_id('switcher_plogin').click()
sleep(2)
bro.find_element_by_id('u').send_keys('账号')
bro.find_element_by_id('p').send_keys('密码')
bro.find_element_by_id('login_button').click()
sleep(5)

page_text = bro.page_source
with open('./Web/qq.html','w',encoding='utf-8')as fp:
    fp.write(page_text)

bro.quit()

说点什么

avatar
  Subscribe  
提醒