【问题标题】:Python requests code gives Javascript disabled or not supported by web browserPython 请求代码使 Javascript 被 Web 浏览器禁用或不支持
【发布时间】:2019-12-06 14:14:22
【问题描述】:

我正在尝试使用公司的 API 获取网页,它在 Postman 中完美运行,但是当我将 Postman 生成的代码放入 python 请求时,它返回不同的响应。

我设置了我的代理并添加了我的基本身份验证,但它仍然无法正常工作

url = "https://www.test.com/confluence/rest/api/content/<id>"

querystring = {"expand":"space,body.view,version,container"}

headers = {
    'Content-Type': "application/json",
    'Authorization': "****",
    'User-Agent': "PostmanRuntime/7.15.2",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Postman-Token': "****",
    'Host': "www.test.com",
    'Cookie': "****",
    'Accept-Encoding': "gzip, deflate",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

response = requests.request("GET", url, headers=headers, params=querystring, proxies=urllib.request.getproxies())

Postman 返回一个 JSON 响应,其中包含整个网页 + ID 和任何其他必要信息。 Python 返回嵌入此错误的 HTML 网页

JavaScript is either disabled in or not supported by the Web browser.
To continue logon, use a Web browser that supports JavaScript or enable JavaScript in your current browser.

【问题讨论】:

标签: python python-requests postman


【解决方案1】:

如果您尝试使用纯粹由 JavaScript 呈现的网页,则使用 selenium 可能对您有用。 这是一个创建可以呈现 JavaScript 的网络浏览器的包。 这里有一些不错的文档:https://selenium-python.readthedocs.io/

安装过程很长,但值得一试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-16
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多