Python请求代码使Javascript禁用或Web浏览器不支持

时间:2019-07-29 09:03:00

标签: python python-requests postman

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

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

"hello"sv.data()

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

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())

1 个答案:

答案 0 :(得分:0)

如果您尝试使用纯JavaScript渲染的网页,则使用硒可能会很有用。 这是一个创建可呈现JavaScript的Web浏览器的程序包。 这里有一些不错的文档:https://selenium-python.readthedocs.io/

安装时间很长,但是值得尝试。

相关问题