search

Home  >  Q&A  >  body text

网页爬虫 - python 脚本遇到session 获取不到cookie?

大家讲道理大家讲道理2907 days ago534

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:03:57

    That cookie is generated by the server when you visit and does not need to be obtained. This cookie is different in nature from the cookie you logged in. The following code is for your reference

    import requests

    import cookielib

    headers = {

    'Accept':'*/*',
    'Accept-Encoding':'gzip, deflate, sdch',
    'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6',
    'Connection':'keep-alive',
    'Content-Type':'application/x-www-form-urlencoded',
    'Host':'query.sse.com.cn',
    'Referer':'http://www.sse.com.cn/disclosure/listedinfo/regular/',
    'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'

    }

    session = requests.Session()
    session.cookies = cookielib.LWPCookieJar('cookiejar')

    HURL = "http://query.sse.com.cn/infodisplay/quryLatestbulletinnew.do?&jsonCallBack=jsonpcallback56537Proporttype2=dqgg& ReportType = All & Begindate = 2016-09-06 & Enddate = 2016-12-06 & Pagehelp.pageSize = 25 & Pagehelp.pageCount = 50&pageHelp.pageNo=1&pageHelp.beginPage=1&pageHelp.cacheSize=1&pageHelp.endPage=5&_=1480932427091"

    print session.get(url=url, headers=headers).text

    reply
    0
  • Cancelreply