Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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请求为同一url GET请求返回不同的头_Python_Http_Http Headers_Python Requests - Fatal编程技术网

python请求为同一url GET请求返回不同的头

python请求为同一url GET请求返回不同的头,python,http,http-headers,python-requests,Python,Http,Http Headers,Python Requests,我多次访问同一个网站,每隔一段时间,请求就会返回完整的页面(从内容长度可以看出)。我已经包含了针对特定请求的不同标题参数 url = "http://www.atpworldtour.com/players/roger-federer/f324/player-activity?year=2016" while True: r = requests.get(url) print r.headers # {... , 'Content-Length': '40940', ... ,

我多次访问同一个网站,每隔一段时间,
请求
就会返回完整的页面(从
内容长度
可以看出)。我已经包含了针对特定请求的不同标题参数

url = "http://www.atpworldtour.com/players/roger-federer/f324/player-activity?year=2016"
while True:
    r = requests.get(url)
    print r.headers

# {... , 'Content-Length': '40940', ... , 'Age': '807', ... , 'Connection': 'keep-alive', ...,  'X-ATP-Server': 'web4', ... , 'Via': '1.1 sng202146 ...', ...}
# {... , 'Content-Length': '40940', ... , 'Age': '807', ... , 'Connection': 'keep-alive', ...,  'X-ATP-Server': 'web4', ... , 'Via': '1.1 sng202146 ...', ...}

...

# {... , 'Content-Length': '40940', ... , 'Age': '808', ... , 'Connection': 'keep-alive', ...,  'X-ATP-Server': 'web4', ... , 'Via': '1.1 sng202146 ...', ...}
# {... , 'Content-Length': '41632', ... , 'Age': '817', ... , 'Connection': 'keep-alive', 'X-Trace': '1B7F99....', ... , 'X-ATP-Server': 'web1', ... , 'Via': '1.1 sng202055 ...', ...}
# {... , 'Content-Length': '40940', ... , 'Age': '812', ... , 'Connection': 'keep-alive', ...,  'X-ATP-Server': 'web4', ... , 'Via': '1.1 sng202146 ...', ...}
# {... , 'Content-Length': '40940', ... , 'Age': '814', ... , 'Connection': 'keep-alive', ...,  'X-ATP-Server': 'web4', ... , 'Via': '1.1 sng202146 ...', ...}

...

我不太了解html,不知道这是否是由于js动态生成的某些页面造成的,但我想强制
请求每次返回长度为41632的页面。我也没有尝试过超时参数,因为请求都正确返回(状态代码
200
)但是长度不同。

考虑到差异是
X-Trace
头,这可能只是
atpworldtour.com
的运营商为了调试目的偶尔跟踪他们的网络堆栈而使用的一些附加头数据。页面本身可能没有太大的不同。遗憾的是,当我去刮页面时e内容实际上是不同的(因此我首先注意到了这个问题)。我将尝试找到一个可复制的缺少内容的示例。考虑到差异是
X-Trace
头,这可能只是
atpworldtour.com
的运营商为了调试目的偶尔跟踪其网络堆栈而使用的一些额外头数据。页面本身可能没有太大的不同。遗憾的是,当我去抓取页面时,内容实际上是不同的(因此我首先注意到了这个问题)。我将尝试找到一个可复制的缺少内容的示例