【问题标题】:Browser simulation - Python 3浏览器模拟 - Python 3
【发布时间】:2012-01-24 19:08:19
【问题描述】:

我需要通过 Python 3 脚本访问一些 HTML 页面,问题是我需要 COOKIE 功能,因此一个简单的 urllib HTTP 请求将不起作用。

有什么想法吗?

【问题讨论】:

    标签: python session browser cookies


    【解决方案1】:

    python3的urllib有cookie支持,看urllib.request.HTTPCookieProcessorhttp.cookiejar

    【讨论】:

      【解决方案2】:

      使用requests

      >>> import requests
      >>> url = 'http://httpbin.org/cookies/set/requests-is/awesome'
      >>> r = requests.get(url)
      
      >>> print r.cookies
      {'requests-is': 'awesome'}
      

      参考:http://docs.python-requests.org/en/latest/user/quickstart/#cookies

      截至几天前,requests supports Python 3,虽然您可能不得不使用develop 分支之一,但不能完全确定上游集成的状态。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-02
        • 2012-12-06
        • 1970-01-01
        • 1970-01-01
        • 2014-03-13
        相关资源
        最近更新 更多