qqzone正常

This commit is contained in:
criseLYJ
2019-03-07 00:09:41 +08:00
parent c425dae7b0
commit 62cd1fc3fb
2 changed files with 39 additions and 47 deletions
-47
View File
@@ -1,47 +0,0 @@
from selenium import webdriver
import time
import requests
# 这个地方是通过观察html代码得到的,因为我先前通过find方法定位switch始终提示我没有这个元素,那么我就猜想它肯定是被隐藏或者嵌套在别的
# frame中了
login_url = 'http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html' \
'&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&' \
'appid=549000912&style=22&target=self&s_url=http%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara' \
'%3Dizone%26specifyurl%3Dhttp%253A%252F%252Fuser.qzone.qq.com%252F1796246076&pt_qr_app=手机QQ空间' \
'&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html' \
'&pt_qr_help_link=http%3A//z.qzone.com/download.html'
login_name = input('请输入QQ号:')
login_password = input('请输入QQ密码:')
# 不知是不是selenium的版本问题还是操作平台问题,如今的selenium安装好了使用webdriver.Firefox()/webdriver.Chrome()可能会报错,在ide下并不会
# 提示webdriver.*。遇到这种情况直接删除python安装目录下的selenium文件夹。这样import selenium.webdriver才是导入的site-packges目录下的webdriver模块
driver = webdriver.Chrome(executable_path='D:/webdriver/chromedriver.exe')
driver.get(login_url)
time.sleep(3)
login_type = driver.find_element_by_id('switcher_plogin')
login_type.click()
username = driver.find_element_by_id('u')
username.clear()
password = driver.find_element_by_id('p')
password.clear()
username.send_keys(login_name)
password.send_keys(login_password)
submit = driver.find_element_by_id('login_button')
submit.click()
time.sleep(5)
cookies = driver.get_cookies()
driver.close()
cookie = [item['name'] + "=" + item['value'] for item in cookies]
cookiestr = '; '.join(item for item in cookie)
headers = {'cookie': cookiestr}
# 验证cookie是否正确
myspace = 'http://user.qzone.qq.com/17962460'
content = requests.get(myspace, headers=headers)
print(content.text)
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
info:
author:CriseLYJ
github:https://github.com/CriseLYJ/
update_time:2019-3-7
"""
import time #用来延时
from selenium import webdriver
driver = webdriver.Chrome() #选择浏览器,此处我选择的Chrome
QQ_NUMBER = input('请输入你的QQ号')
PASSWORD = input('请输入你的QQ密码')
driver.get('http://i.qq.com/')
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_name('u').clear()
driver.find_element_by_name('u').send_keys(QQ_NUMBER) # 此处输入你的QQ号
driver.find_element_by_name('p').clear()
driver.find_element_by_name('p').send_keys(PASSWORD) # 此处输入你的QQ密码
driver.execute_script("document.getElementById('login_button').parentNode.hidefocus=false;")
driver.find_element_by_xpath('//*[@id="loginform"]/div[4]/a').click()
driver.find_element_by_id('login_button').click()
time.sleep(10) # 因为我曾经是QQ会员,所以每次登陆时都会提醒我要不要再续费的弹窗...
driver.find_element_by_id('dialog_button_1').click() # 这个地方是我把那个弹窗给点击了,配合上面的延时用的,延时是等待那个弹窗出现,然后此处点击取消
btns = driver.find_elements_by_css_selector('a.item.qz_like_btn_v3') # 此处是CSS选择器
for btn in btns:
btn.click()