Home > other >  Release login python simulation tasks, through pass by don't miss
Release login python simulation tasks, through pass by don't miss

Time:09-28

1, simulation portal: https://passport.zhihuishu.com/login? service=https://onlineservice.zhihuishu.com/login/gologin
2, the log is completed, the get request access 'https://onlineservice.zhihuishu.com/login/getLoginUserInfo' this interface
Success: only returns a status=1
Failure: return to the 403 delegates, to simulate the failure, at the same time, it returns the status=1, then bring a token
Requirements: the python language, simulating the login requests/selenium

CodePudding user response:

Wrote a landing simulation attracts, then draw the following code, + the selenium in python, you can refer to
 
The from the selenium import webdriver
The from selenium.webdriver.com mon. Keys import keys
The from selenium.webdriver.com mon. By the import by
The from the selenium. Webdriver. Support. The UI import WebDriverWait
The from the selenium. Webdriver. Support the import expected_conditions as EC
The import time
The from bs4 import BeautifulSoup

Def bsNCProblem () :
Chrome_driver_path="' E: \ chromedriver exe '"'
Driver=webdriver. Chrome (executable_path=chrome_driver_path)
Ncusername NCPWD='* * *', '* * *
Url='https://ac.nowcoder.com/acm/contest/950/K'
Driver. The get (url)

Try:
Username_element=WebDriverWait (driver, 10) until (
EC. Presence_of_element_located ((By ID, "jsEmailIpt"))
)
Pwd_element=driver. Find_element_by_id (' jsPasswordIpt ')
Loginbtn_element=driver. Find_element_by_id (' jsLoginBtn ')

Username_element. Send_keys (ncusername)
Pwd_element. Send_keys (NCPWD)

Loginbtn_element. Click ()
Driver. The refresh ()

Time. Sleep (3)

Title_element=driver. Find_element (By CLASS_NAME, 'terminal - topic - the title')
Limit_element=driver. Find_element (By CLASS_NAME, 'the subject - item - wrap)
Describe_element=driver. Find_element (By CLASS_NAME, 'the subject - the describe')
Print (title_element. Text)
Print (limit_element. Text)
Print (describe_element. Text)

Driver. The close ()
Finally:
Pass


If __name__=="__main__" :
BsNCProblem ()

CodePudding user response:

# - * - coding: utf-8 - * -
The import json

The import requests



The import time


The from the selenium import webdriver
The from selenium.webdriver.com mon. Desired_capabilities import DesiredCapabilities
The from selenium.webdriver.com mon. Action_chains import ActionChains
If __name__=="__main__ ':
Dcap=dict (DesiredCapabilities PHANTOMJS)
Dcap [" phantomjs. Page. Settings. UserAgent "]=(
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 "
)
# browser=webdriver. Chrome (executable_path="/Users/houduan/chromedriver")
# browser=webdriver. PhantomJS (executable_path=' ')
Browser=webdriver. Firefox (executable_path="/Users/houduan/geckodriver")
Url="https://passport.zhihuishu.com/login? service=https://onlineservice.zhihuishu.com/login/gologin '
The get (url)
Time. Sleep (1)

# login and machine configuration information
The username="130 xxxx7316 # account
"Passwd="XXXXX" # password

ActionChains (browser). Move_by_offset (600, 0). The perform ()
Elem=the find_element_by_id (" lUsername ")
Elem. Send_keys (username)

ActionChains (browser). Move_by_offset (300, 0). The perform ()
Elem=the find_element_by_id (" lPassword ")
Elem. Send_keys (passwd)

Elem=the find_element_by_class_name (" wall - sub - BTN ")
Elem. Click ()
Time. Sleep (3)
The get (' https://onlineservice.zhihuishu.com/login/getLoginUserInfo ')
The session=requests. The session ()
Cookies=the get_cookies ()
For the item in the cookies:
Session. Cookies. Set (item (' name '), the item [' value '])
Headers={
'Connection' : 'keep - the alive',
'the user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; The rv: 73.0) Gecko/20100101 Firefox/73.0 '
}
Userinfo_url='http://onlineservice.zhihuishu.com/login/getLoginUserInfo'
Userinfo_data=https://bbs.csdn.net/topics/json.loads (session. Get (userinfo_url
And headers=headers
). The text)
Print (userinfo_data)
  • Related