抓取需要登录的中文网站时出错

2024-09-28 05:19:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉python和scraping,但需要从需要登录的中文数据库中获取信息。我借鉴了这里的一些技术,但似乎无法让我的脚本正确登录。谢谢你的帮助

登录页中的html:

#<input name="txtUserName" type="text" id="txtUserName" tabindex="1" class="input_txt" errortag="yzm-error" errorempty="请输入用户名">`
#<input name="txtPassword" type="password" id="txtPassword" tabindex="2" class="input_txt" errortag="yzm-error" errorempty="请输入密码" autocomplete="false">

代码:

import requests

login_url = "http://mall.cnki.net/Login.aspx?p=http%3a%2f%2fmall.cnki.net%2findex.aspx"
request_url = "http://mall.cnki.net/reference/ref_readerItem.aspx?bid=&recid=R2008070580000085"

payload = {"txtUserName": "test112233", "txtPassword": "test135"}

with requests.Session() as session:
    post = session.post(login_url, data=payload, verify=True)
    r = session.get(request_url)
    print(r.text)

Tags: textnametxtidurlinputsessiontype

热门问题