返回信息流百度了很久总是登陆失败,不知道是什么问题,初学小白一枚,希望有大神能指点一二,不胜感激。写的代码发在帖子下面吧。。。
这是一条镜像帖。来源:北邮人论坛 / python / #21223同步于 2018/3/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
Python爬虫抓取校园网数据的问题
oybalabala
2018/3/26镜像同步13 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
import urllib.request
import urllib.parse
import random
url='https://auth.bupt.edu.cn/authserver/login?service=http://my.bupt.edu.cn/index.portal'
iplist = ['27.40.155.104:61234', '61.135.217.7:80', '122.114.31.177:808', '125.118.241.190:6666']
# headers 信息,从fiddler上或你的浏览器上可复制下来
headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Content-Length': '136',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'auth.bupt.edu.cn',
'rigin': 'https://auth.bupt.edu.cn',
'Referer': 'https://auth.bupt.edu.cn/authserver/login?service=http://my.bupt.edu.cn/index.portal',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'}
# POST请求的信息,填写你的用户名和密码
value = {'username': '***',
'password':'***',
'lt': 'LT-2385055-35ybie13jJScvOgrqzUvocNAPFqlUD-1521609324240',
'execution': 'e1s1',
'_eventId': 'submit',
'rmShown': '1'}
proxy_support = urllib.request.ProxyHandler({'http': random.choice(iplist)})
data = urllib.parse.urlencode(value).encode('utf8')
response = urllib.request.Request(url, data=data,headers=headers)
opener = urllib.request.build_opener(proxy_support)
html =opener.open(response)
print(html.geturl())
if html.geturl() == "http://my.bupt.edu.cn/index.portal":
print ("登录成功")
result = html.read().decode('utf8')
print(result)
else:
print('登陆失败')
import urllib2
import urllib
url = "http://10.3.8.211/"
map = {}
map["DDDDD"] = "name"
map["upass"] = "password"
map["0MKKey"] = ""
data = urllib.urlencode(map)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
page = response.read()
啊?这个需要给网关发请求嘛?
【 在 fuxuemingzhu 的大作中提到: 】
: import urllib2
: import urllib
:
明明简单抓个包就能看到啊~
```
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
data = {'DDDDD': 'schoolid',
'upass': 'password',
'0MKKey': ''}
a = requests.post('http://10.3.8.211', data=data)
```
就想试着给我们校园网首页发个请求,不是要登录的么,用户名是学号,密码自己设的那个
【 在 fuxuemingzhu 的大作中提到: 】
: 你把你要请求的网址和要爬去的数据说明白一点