Reptile project combat ten: simulated landing writer's assistant

Simulated landing writer's assistant

aims

Since you have to enter your account and password every time you log in, it is too troublesome. In order to save time, use the automation control software to control the browser to log in to the writer assistant.

Project preparation

Software: Pycharm
third-party library: selenium
Website address: https://write.qq.com/public/login.html?authortip=0

Project Analysis

Open the website.
Insert picture description here

This has account login, QQ login and WeChat login. Because I used QQ to register before, so I used QQ to log in.
Insert picture description here
Click to log in to QQ.
Will get such a page.
Insert picture description here
Copy the URL for later use.

Code

#导入第三方库selenium
from selenium import webdriver
#引入自动化控制程序chromedriver.exe
driver=webdriver.Chrome(executable_path=r'C:\Users\acer\AppData\Local\Google\Chrome\Application\chromedriver.exe')
driver.get('https://graph.qq.com/oauth2.0/show?which=Login&display=pc&g_ut=1&response_type=code&redirect_uri=https%3A%2F%2Fptlogin.qidian.com%2Flogin%2Fqqconnectcallback%3Freturnurl%3Dhttps%253A%252F%252Fwrite.qq.com%253Fartidx%253D0%26appid%3D34%26areaid%3D1006%26jumpdm%3Dyuewen%26popup%3D1%26ajaxdm%3Dyuewen%26target%3Dtop%26ticket%3D1%26ish5%3D0%26auto%3D1%26autotime%3D7&client_id=101481755')#刚刚复制的url

Test it to
Insert picture description here
maximize the display.

driver.maximize_window()#最大化窗口

Switch iframe
Insert picture description here

Insert picture description here
Copy its id.

#切换iframe
ptlogin_iframe=driver.find_element_by_id('ptlogin_iframe')
driver.switch_to.frame(ptlogin_iframe)#switch_to.frame()切换iframe,之前用的是switch_to_iframe()现在修改了
driver.find_element_by_id('switcher_plogin').click()#复制下来的id  .click()模拟鼠标点击

have a test.
Insert picture description here
Next simulate input account and password.

driver.find_element_by_xpath('//*[@id="u"]').send_keys('账号')
driver.find_element_by_xpath('//*[@id="p"]').send_keys('密码')
driver.find_element_by_xpath('//*[@id="login_button"]').click()#模拟点击登录

Effect display

Insert picture description here
login successful.
I did not encounter the verification code problem here, wait for the next test to try the verification code problem.
The complete code is as follows:

from selenium import webdriver
driver=webdriver.Chrome(executable_path=r'C:\Users\acer\AppData\Local\Google\Chrome\Application\chromedriver.exe')
driver.get('https://graph.qq.com/oauth2.0/show?which=Login&display=pc&g_ut=1&response_type=code&redirect_uri=https%3A%2F%2Fptlogin.qidian.com%2Flogin%2Fqqconnectcallback%3Freturnurl%3Dhttps%253A%252F%252Fwrite.qq.com%253Fartidx%253D0%26appid%3D34%26areaid%3D1006%26jumpdm%3Dyuewen%26popup%3D1%26ajaxdm%3Dyuewen%26target%3Dtop%26ticket%3D1%26ish5%3D0%26auto%3D1%26autotime%3D7&client_id=101481755')
driver.maximize_window()
#切换iframe
ptlogin_iframe=driver.find_element_by_id('ptlogin_iframe')
driver.switch_to.frame(ptlogin_iframe)
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_xpath('//*[@id="u"]').send_keys('账号')
driver.find_element_by_xpath('//*[@id="p"]').send_keys('密码')
driver.find_element_by_xpath('//*[@id="login_button"]').click()

Guess you like

Origin blog.csdn.net/qq_44862120/article/details/107842293