V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dsp2138
V2EX  ›  Python

POST 请求这样构建对不对?为啥总不成功

  •  1
     
  •   dsp2138 · 2016-03-12 18:35:09 +08:00 · 5621 次点击
    这是一个创建于 3179 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import requests
    import json

    url='http://www.spprec.com/sczw/jyfwpt/005001/005001001/MoreInfo.aspx?CategoryNum=005001001'
    s = requests.session()

    postdata={'__EVENTTARGET': 'MoreInfoList1$Pager', '__EVENTARGUMENT': '3', '__VIEWSTATE': '/wEPDwUKLTU4MzUzNjg5NA9kFgICAQ9kFgJmDw8WBh4LYmdDbGFzc05hbWUFCE1pZGRsZUJnHgtjYXRlZ29yeU51bQUJMDA1MDAxMDAxHgZzaXRlaWQCAWQWAmYPZBYEAgIPZBYCZg9kFgJmDzwrAAsCAA8WCh4LXyFJdGVtQ291bnQCFB4IRGF0YUtleXMWAB4JUGFnZUNvdW50AgEeFV8hRGF0YVNvdXJjZUl0ZW1Db3VudAIUHghQYWdlU2l6ZQIUZAEUKwADZGQ8KwAEAQAWAh4HVmlzaWJsZWcWAmYPZBYoAgIPZBYGZg9kFgJmDxUBKDxpbWcgc3JjPSIvc2N6dy9pbWFnZXMvZG90cy9kb3RfNDAuZ2lmIj5kAgEPZBYCZg8VAasCPGEgaHJlZj0iL3NjencvSW5mb0RldGFpbC9EZWZhdWx0LmFzcHg/SW5mb0lEPTFhMmEzODAwLTY5MWUtNDY4YS1iMmE0LWM0Mzg4ZDIyNGUzNCZDYXRlZ29yeU51bT0wM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pWw77yaPGZvbnQgY29sb3I9ImJsdWUiPjxiPjM2OTI1PC9iPjwvZm9udD4g5oC76aG15pWw77yaPGZvbnQgY29sb3I9ImJsdWUiPjxiPjE4NDc8L2I+PC9mb250PiDlvZPliY3pobXvvJo8Zm9udCBjb2xvcj0icmVkIj48Yj4zPC9iPjwvZm9udD4eCUltYWdlUGF0aAUSL3NjencvaW1hZ2VzL3BhZ2UvZGRkYR6H9++CccGv2mwKZyEYsm9PcbU=', '__CSRFTOKEN': '/wEFJGJlODIyZDM0LTJmODgtNGQwMS1hNGQxLTJhMzdiZTViZThiMg=='}

    headers={'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://www.spprec.com/sczw/jyfwpt/005001/005001001/MoreInfo.aspx?CategoryNum=005001001', 'Accept-Language': 'zh-CN,zh;q=0.8', 'Content-Type': 'application/x-www-form-urlencoded', 'Origin': 'http://www.spprec.com', 'Connection': 'keep-alive', 'Host': 'www.spprec.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'}
    r=requests.get(url)

    resp = s.post(url,headers=headers,cookies=r.cookies)
    49 条回复    2016-03-13 09:56:31 +08:00
    dsp2138
        1
    dsp2138  
    OP
       2016-03-12 18:37:49 +08:00
    具体 postdata 为啥那么长,我也很纳闷我是不是搞错了!
    但这个网站竟然将网页全文做为一个变量用 js submit 传送了!!

    大虾帮忙分析下,这个 URL 的 post 我这样做对不对!
    hansnow
        2
    hansnow  
       2016-03-12 18:42:08 +08:00
    resp = s.post(url,headers=headers,cookies=r.cookies)

    data 去哪儿了?
    trotyl
        3
    trotyl  
       2016-03-12 18:43:37 +08:00
    你的 postdata 根本就没用过。。不懂你是要干什么。。
    dsp2138
        4
    dsp2138  
    OP
       2016-03-12 18:45:36 +08:00
    @hansnow esp = s.post(url,data=posdate,theaders=headers,cookies=r.cookies)
    抱歉,刚修改了,直接复制了!
    这样也不行的
    dsp2138
        5
    dsp2138  
    OP
       2016-03-12 18:46:15 +08:00
    @trotyl 源码复制时错了,抱歉
    resp = s.post(url,data=posdate,theaders=headers,cookies=r.cookies)
    crab
        6
    crab  
       2016-03-12 18:47:52 +08:00
    __VIEWSTATE 这个参数值是动态的吧?
    dsp2138
        7
    dsp2138  
    OP
       2016-03-12 18:50:03 +08:00
    @crab 这个我 base64 解码看了下,就是当前页的全文的 html 代码!
    具体为啥这么做很是不理解!
    Strikeactor
        8
    Strikeactor  
       2016-03-12 18:50:44 +08:00   ❤️ 1
    dsp2138
        9
    dsp2138  
    OP
       2016-03-12 18:52:35 +08:00
    @Strikeactor 我试试看
    xuzywozz
        10
    xuzywozz  
       2016-03-12 18:55:01 +08:00
    heasers 不全?
    dsp2138
        11
    dsp2138  
    OP
       2016-03-12 18:56:13 +08:00
    @xuzywozz 我应该把 get 得到的 headers 都添加上吗?
    bdbai
        12
    bdbai  
       2016-03-12 21:23:19 +08:00 via iPhone
    这一大串是 ASP.NET WebForm 生成的。你可以直接访问页面得到那串东西,然后模拟浏览器请求 POST 这样也许会好一点。
    xuzywozz
        13
    xuzywozz  
       2016-03-12 21:34:46 +08:00
    @dsp2138 全加上试试 我遇到几次问题都是 headers 不全造成的
    dsp2138
        14
    dsp2138  
    OP
       2016-03-12 21:47:47 +08:00
    @bdbai 我大概也看明白了, cookies 里面的__CSRFCOOKIE ,和 data 里面的__CSRFTOKEN 是保持一致的!
    只是__CSRFTOKEN 的 value 使用了 base64 加密,但又不完全是!__CSRFCOOKIE 的 base64 码和__CSRFTOKEN 不一致!正在琢磨呢
    mhycy
        15
    mhycy  
       2016-03-12 22:03:42 +08:00
    能不能说说在干啥?发了那么多次代码没次对的。。。。囧
    dsp2138
        16
    dsp2138  
    OP
       2016-03-12 22:05:25 +08:00
    @mhycy resp = s.post(url,data=data,cookies=cookies,headers=headers)
    mhycy
        17
    mhycy  
       2016-03-12 22:09:30 +08:00
    @dsp2138 要干啥?
    rcmerci
        18
    rcmerci  
       2016-03-12 22:15:14 +08:00
    卧槽点进来吓尿了
    just1
        19
    just1  
       2016-03-12 22:15:38 +08:00 via Android
    header 有的参数是不能加的
    dsp2138
        20
    dsp2138  
    OP
       2016-03-12 22:20:07 +08:00
    @just1 请教,哪些是不能加的?本人对这方面学习甚少!
    谢谢
    just1
        21
    just1  
       2016-03-12 22:34:47 +08:00 via Android
    @dsp2138 我也忘了,,,一个个测试吧。具体的情况就是 python 命令行下一个请求一直无反应(ctrl+c)也没用
    mhycy
        22
    mhycy  
       2016-03-12 22:47:42 +08:00
    bdbai
        23
    bdbai  
       2016-03-12 22:48:20 +08:00
    这是我写的一个实现:
    https://gist.github.com/bdbai/cfd44c612ca154a62092

    新手上路,请各位轻喷。
    mhycy
        24
    mhycy  
       2016-03-12 22:49:41 +08:00
    https://gist.github.com/anonymous/e837f2f5d9c6c57d7db8
    貌似是 https 才能正常加载。。囧
    awanabe
        25
    awanabe  
       2016-03-12 22:59:35 +08:00
    你给的是 dict , 要用 json dump 一下吧
    Comdex
        26
    Comdex  
       2016-03-12 23:06:40 +08:00
    楼主在搞模拟登录正方教务系统?
    dsp2138
        27
    dsp2138  
    OP
       2016-03-12 23:23:46 +08:00
    /wEFJGY5NjIzYzdkLTI3OGQtNDliYy04YzJiLTNmMjZkODdlMTI1Yw==

    f9623c7d-278d-49bc-8c2b-3f26d87e125c
    是 base64 加密和解密的关系,但 /wEFJGY5NjIzYzdkLTI3OGQtNDliYy04YzJiLTNmMjZkODdlMTI1Yw==解密后开始的几个字符,怎么处理?
    这个怎么用 base64 加密和还原?
    mhycy
        28
    mhycy  
       2016-03-12 23:25:34 +08:00
    @dsp2138 话说,你不是要抓页面么?
    dsp2138
        29
    dsp2138  
    OP
       2016-03-12 23:42:14 +08:00
    @mhycy 是,需要取得下一页的内容
    mhycy
        30
    mhycy  
       2016-03-12 23:43:27 +08:00
    @dsp2138 已经给你写出来了
    bdbai
        31
    bdbai  
       2016-03-12 23:49:38 +08:00 via iPhone
    @dsp2138 网页里面有个分页组件,用正则匹配一下就能读到分页数据了。上面给你写了一个直接读分页页面的。
    dsp2138
        32
    dsp2138  
    OP
       2016-03-12 23:53:13 +08:00
    @bdbai 谢谢, github 我这里没 vpn ,无法访问!
    dsp2138
        33
    dsp2138  
    OP
       2016-03-12 23:54:49 +08:00
    @mhycy 谢谢了,源码能放到国内吗, github 实在访问不了
    mhycy
        34
    mhycy  
       2016-03-12 23:55:27 +08:00
    @dsp2138
    看不到就不能留个言么。。囧

    #coding=utf-8
    import json
    import requests
    import re

    class spprec(object):
    def __init__(self, url):
    self.session = requests.session()
    self.session.headers.update({
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'
    })
    self.url = url
    self.post_data = {}

    def getInfo(self, num):
    if len(self.post_data) == 0:
    res = self.session.get(self.url)
    else:
    self.post_data['__EVENTARGUMENT'] = num
    self.post_data["__EVENTTARGET"] = "MoreInfoList1$Pager"
    res = self.session.post(url=self.url, data=self.post_data)

    result = re.findall('<input type="hidden" name="([^"]+)" id="([^"]+)" value="([^"]+)" />', res.text, re.S)
    post_data = {}
    for item in result:
    post_data.update({item[0]: item[2]})
    self.post_data = post_data

    result = re.findall('<a href="(/sczw/InfoDetail/Default.aspx[^"]+)" target="_blank" title="([^"]+)"', res.text, re.S)
    return result

    obj = spprec("http://www.spprec.com/sczw/jyfwpt/005001/005001001/MoreInfo.aspx?CategoryNum=005001001")
    for i in xrange(1, 5):
    data = obj.getInfo(i)
    for item in data:
    print item[1]
    mhycy
        35
    mhycy  
       2016-03-13 00:01:41 +08:00   ❤️ 1
    #coding=utf-8
    import json
    import requests
    import re


    class spprec(object):
    \tdef __init__(self, url):
    \t\tself.session = requests.session()
    \t\tself.session.headers.update({
    \t\t\t'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'
    \t\t})
    \t\tself.url = url
    \t\tself.post_data = {}

    \tdef getInfo(self, num):
    \t\tif len(self.post_data) == 0:
    \t\t\tres = self.session.get(self.url)
    \t\telse:
    \t\t\tself.post_data['__EVENTARGUMENT'] = num
    \t\t\tself.post_data["__EVENTTARGET"] = "MoreInfoList1$Pager"
    \t\t\tres = self.session.post(url=self.url, data=self.post_data)

    \t\tresult = re.findall('<input type="hidden" name="([^"]+)" id="([^"]+)" value="([^"]+)" />', res.text, re.S)
    \t\tpost_data = {}
    \t\tfor item in result:
    \t\t\tpost_data.update({item[0]: item[2]})
    \t\tself.post_data = post_data

    \t\tresult = re.findall('<a href="(/sczw/InfoDetail/Default.aspx[^"]+)" target="_blank" title="([^"]+)"', res.text, re.S)
    \t\treturn result

    obj = spprec("http://www.spprec.com/sczw/jyfwpt/005001/005001001/MoreInfo.aspx?CategoryNum=005001001")
    for i in xrange(1, 5):
    \tdata = obj.getInfo(i)
    \tfor item in data:
    \t\tprint item[1]

    缩进全没了,请自行替换吧,\t 对应 4 个空格或者一个 tab
    dsp2138
        36
    dsp2138  
    OP
       2016-03-13 00:07:16 +08:00
    @mhycy 谢谢,我试试看
    dsp2138
        37
    dsp2138  
    OP
       2016-03-13 00:25:13 +08:00
    @mhycy 成功了!
    谢谢你!
    能简单说下原理吗?
    谢谢老师
    bdbai
        38
    bdbai  
       2016-03-13 00:25:36 +08:00 via iPhone   ❤️ 1
    mhycy
        39
    mhycy  
       2016-03-13 00:29:33 +08:00   ❤️ 1
    @dsp2138 不管是我的还是 @bdbai 的都是抓出那个数据重新提交上去而已。。
    我的那段代码比较直白 @bdbai 那段代码比较简洁

    这个写法是很多 asp/.net 站点都有的,具体是什么原理没写过 asp/.net 并不了解
    事实上只要看看源代码抓一次请求就知道怎么发了
    bdbai
        40
    bdbai  
       2016-03-13 00:36:05 +08:00 via iPhone   ❤️ 1
    @mhycy ASP.NET WebForm 的理念就是把网页当成 WinForm 那样的窗体对待,服务端开发能轻松不少,但缺点很明显,每次触发事件都会把整个网页状态都上传、下载一遍。现代一点的网站都不会用它。
    dsp2138
        41
    dsp2138  
    OP
       2016-03-13 00:37:08 +08:00
    @mhycy post 中__VIEWSTATE 和__CSRFTOKEN 不用管吗?后台没有对这里个 input 进行验证?

    我提交的过程基本和你一致,但总是获取到的都是第一页

    谢谢,在仔细看看你的源码
    dsp2138
        42
    dsp2138  
    OP
       2016-03-13 00:37:54 +08:00
    @bdbai 谢谢
    mhycy
        43
    mhycy  
       2016-03-13 00:43:14 +08:00
    @bdbai 看上去这个 POST 像是页面验证的一部分。。
    @dsp2138 生成的 POST_DATA 就是这两个参数的数据,用正则表达式提取出来的。
    仔细看看代码吧,我这个已经写得比较直白了。
    bdbai
        44
    bdbai  
       2016-03-13 00:48:53 +08:00 via iPhone
    @mhycy 嗯有 CSRF 处理。 ViewState 是给服务器还原"窗体"的,不传好像也没问题。
    dsp2138
        45
    dsp2138  
    OP
       2016-03-13 00:50:58 +08:00
    @bdbai @mhycy

    我也成功了!
    发现自己还是对 requests 模块中的 session 不理解!!
    发送的 cookies 有问题!

    @bdbai 这类的网站国内省级站又近十家都是同一家公司做的!因此界面报告导航分页的代码都是一致!

    -------------------------------
    我自己的代码

    ----------------
    import requests
    import json
    from bs4 import BeautifulSoup

    url='http://www.spprec.com/sczw/jyfwpt/005001/005001001/MoreInfo.aspx?CategoryNum=005001001'
    s = requests.session()
    s.headers.update({ 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36' })
    r=s.get(url)
    soup=BeautifulSoup(r.text,'html5lib')
    __CSRFTOKEN=soup.find('input',id='__CSRFTOKEN').attrs['value']
    __VIEWSTATE=soup.find('input',id='__VIEWSTATE').attrs['value']
    __EVENTTARGET='MoreInfoList1$Pager'
    __EVENTARGUMENT=4
    postdata={'__EVENTTARGET':__EVENTTARGET,'__EVENTARGUMENT':__EVENTARGUMENT,'__CSRFTOKEN':__CSRFTOKEN,'__VIEWSTATE':__VIEWSTATE}
    resp=s.post(url,postdata)
    bdbai
        46
    bdbai  
       2016-03-13 00:55:49 +08:00 via iPhone
    @dsp2138 Session 会帮你处理好 Cookie 的问题。
    HanSonJ
        47
    HanSonJ  
       2016-03-13 01:07:49 +08:00
    @Comdex 哈哈我看到这么长一串也是第一时间想起方正
    dsp2138
        48
    dsp2138  
    OP
       2016-03-13 09:52:50 +08:00
    谢谢各位老师的及时回复
    shyling
        49
    shyling  
       2016-03-13 09:56:31 +08:00 via iPad
    viewstate 这么长是很正常的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1177 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:58 · PVG 01:58 · LAX 09:58 · JFK 12:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.