三十八、 实战– 目标网站登录页面参数获取
登录v2ex网站
网址:https://www.v2ex.com/signin
示例代码
# 1、因为用户名和密码和验证码的name都是随机的,所以我们要先获取网页源代码,然后提取出其中的name值。
# 2、获取到了name和once的值以后,再通过调用https://www,v2ex.com/signin接口,把数据通过post请求发送过去。
# 3、还需要使用云打码平台去自动识别验证码。
import requests
from lxml import etree
login_url = "https://www.v2ex.com/signin"
headers = {
"User - Agent": "Mozilla /5.0(Windows NT 6.1;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 79.0.3945.130Safari/ 537.36",
"referer":"https://www.v2ex.com/signin"
}
resp = requests.get(login_url, headers=headers)
# print(resp.text)
html = resp.text
parser = etree.HTML(html)
inputs = parser.xpath("//form[@action='/signin']//input")
userInput = inputs[0]
passwordInput = inputs[1]
captchaInput = inputs[2]
onceInput = inputs[3]
# for input in inputs:
# input_text = etree.tostring(input)
# print(input_text)
# print("="*30)
userName = userInput.get('name')
passwordName = passwordInput.get('name')
captchaName = captchaInput.get('name')
onceValue = onceInput.get('value')
data = {
userName: 'hyever',
passwordName: 'abcabc',
"once": onceValue,
'next': '/'
}
上一篇文章 第五章 爬虫进阶(三十七) 2020-02-24 地址:
https://www.jianshu.com/p/8eb5412b90ac
下一篇文章 第五章 爬虫进阶(三十九) 2020-02-26 地址:
https://www.jianshu.com/p/e492e1501a67
以上资料内容来源网络,仅供学习交流,侵删请私信我,谢谢。