Created
February 26, 2021 02:28
-
-
Save 117503445/a02ed3058893aa951560e3ea59b88dbf to your computer and use it in GitHub Desktop.
Python 问卷星模拟登陆获取 SojumpSurvey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from lxml import etree | |
def get_SojumpSurvey(username: str, password: str) -> str: | |
''' | |
模拟问卷星登录,获得 SojumpSurvey | |
多次调用需间隔 40 s | |
''' | |
SERVERID = requests.get( | |
'https://www.wjx.cn/css/index.css').cookies.get_dict()['SERVERID'] | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', | |
} | |
html = etree.HTML(requests.get( | |
'https://www.wjx.cn/login.aspx', headers=headers).text) | |
__VIEWSTATE = html.xpath('//*[@id="__VIEWSTATE"]')[0].get('value') | |
__EVENTVALIDATION = html.xpath( | |
'//*[@id="__EVENTVALIDATION"]')[0].get('value') | |
cookies = { | |
'SERVERID': SERVERID, | |
} | |
data = { | |
'__VIEWSTATE': __VIEWSTATE, | |
'__EVENTVALIDATION': __EVENTVALIDATION, | |
'UserName': username, | |
'Password': password, | |
'LoginButton': '登 录' | |
} | |
response = requests.post('https://www.wjx.cn/login.aspx', headers=headers, | |
cookies=cookies, data=data, allow_redirects=False) | |
SojumpSurvey = response.cookies.get_dict()['SojumpSurvey'] | |
return SojumpSurvey | |
def main(): | |
SojumpSurvey = get_SojumpSurvey('用户名', '密码') | |
print(SojumpSurvey) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment