我用请求库登录一个网站。我试过用刮痧,效果很好。但我不尝试处理请求。我得到的是主页的内容,而不是登录后的页面。当我获取url后,url()方法不正确。代码如下
import requests
from bs4 import BeautifulSoup
r=requests.get("http://collegekart.in/login")
c=r.content
soup=BeautifulSoup(c,"html.parser")
token=soup.find("meta",{"name":"csrf-token"})
print(token)
tok=token['content']
print(tok)
s=requests.session()
login={"username":'fdgdgfdgdfgdfg@gmail.com',"password":'dgfdgdfgfdgdfgd',"csrf-token":tok}
s.post("http://collegekart.in/login",data=login)
t=s.get("http://collegekart.in/users")
print(t.url)
sop=BeautifulSoup(t.content,"html.parser")
print(sop.prettify())
我正在获取“的输出内容”大学生卡丁车“而不是”collegekart.in/users. 在
试试看。为了完成一个简单的任务,你做了很多不必要的事情。但是,当您登录时,您可以找到显示一些项目的网页。我也勉强拿到了冠军。在
填充结果的部分输出:
^{pr2}$您可以简单地使用get()方法。在中,对登录凭据使用params属性。在
相关问题 更多 >
编程相关推荐