Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python抓取响应数据_Python_Web Scraping - Fatal编程技术网

Python抓取响应数据

Python抓取响应数据,python,web-scraping,Python,Web Scraping,我想拿一个特定网站的回复数据。 我有这个网站: 如果我打开browser Debugger控制台,我会看到一个posr请求,它会给出json响应: 在python中,我如何通过抓取网站来接受这种响应? 谢谢显然,Web服务有一个PHPSESSID验证,因此我们需要首先使用适当的用户代理获取它: import requests import json headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebK

我想拿一个特定网站的回复数据。 我有这个网站: 如果我打开browser Debugger控制台,我会看到一个posr请求,它会给出json响应:

在python中,我如何通过抓取网站来接受这种响应?
谢谢

显然,Web服务有一个
PHPSESSID
验证,因此我们需要首先使用适当的用户代理获取它:

import requests
import json

headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'
}
r = requests.get('https://enjoy.eni.com/it/milano/map/', headers=headers)
session_id = r.cookies['PHPSESSID']
headers['Cookie'] = 'PHPSESSID={};'.format(session_id)
res = requests.post('https://enjoy.eni.com/ajax/retrieve_vehicles', headers=headers, allow_redirects=False)
json_obj = json.loads(res.content)

你好,尤哈内斯。是的,我刚刚尝试了我的浏览器和作品的PHPSESSID。但我也尝试通过CookieLib检索该值,但在检索该值后,如果我根据请求将其传递给网站的响应eis html,而不是json@APPGIS知道了。我已经更新了我的答案。显然,我们只需要在第一个请求中添加
用户代理
,就可以获得正确的cookie