我已经使用POST请求在python中编写了一些代码以从网页中获取特定数据。但是,当我运行它时,除了空白控制台外,没有任何结果。我试图相应地填写请求参数。也许,我不能注意到哪些应该包含在参数中。我正在处理的页面在其右侧面板中包含多个图像。点击图片时,我在这里谈论的请求被发送到服务器,并将结果返回并显示有关其下的风味的新信息。我的目标是解析连接到每个图像的所有风味。无论如何,我试图附上所有必要的事情,以找出我失踪的事情。提前致谢。POST请求给出空结果
这是我从Chrome开发者工具一定要准备POST请求:
===================================================================================
General:
Request URL:https://www.optigura.com/product/ajax/details.php
Request Method:POST
Status Code:200 OK
Response Headers:
Cache-Control:no-store, no-cache, must-revalidate
Cache-Control:max-age=0, no-cache, no-store, must-revalidate
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:782
Content-Type:text/html; charset=utf-8
Request Headers:
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:34
Content-Type:application/x-www-form-urlencoded
Cookie:OGSESSID=s1qqd0euokbfrdub9pf2efubh1; _ga=GA1.2.449310094.1501502802; _gid=GA1.2.791686763.1501502802; _gat=1; __atuvc=1%7C31; __atuvs=597f1d5241db0352000; beyable-TrackingId=499b4c5b-2939-479b-aaf0-e5cd79f078cc; aaaaaaaaa066e9a68e5654b829144016246e1a736=d5758131-71db-41e1-846d-6d719d381060.1501502805122.1501502805122.$bey$https%3a%2f%2fwww.optigura.com%2fuk%2fproduct%2fgold-standard-100-whey%2f$bey$1; aaaaaaaaa066e9a68e5654b829144016246e1a736_cs=; aaaaaaaaa066e9a68e5654b829144016246e1a736_v=1.1.0; checkloc-uk=n
Host:www.optigura.com
Origin:https://www.optigura.com
Referer:https://www.optigura.com/uk/product/gold-standard-100-whey/
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data:
opt:flavor
opt1:207
opt2:47
ip:105
=======================================================================================
这里就是我,试图:
import requests
from lxml import html
payload = {"opt":"flavor","opt1":"207","opt2":"47","ip":"105"}
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36'}
response = requests.post("https://www.optigura.com/product/ajax/details.php", params = payload, headers = headers).text
print(response)
原来这是链接到网页: https://www.optigura.com/uk/product/gold-standard-100-whey/
您不在POST主体中发送值,'params'设置URL查询参数。改用'data'。 –