我有一个url http://www.vbb.de/de/datei/GTFS_VBB_Nov2015_Dez2016.zip,它将我“重定向”到http://images.vbb.de/assets/ftp/file/286316.zip。在引号中重定向,因为python说没有重定向:
In [51]: response = requests.get('http://www.vbb.de/de/datei/GTFS_VBB_Nov2015_Dez2016.zip')
...: if response.history:
...: print "Request was redirected"
...: for resp in response.history:
...: print resp.status_code, resp.url
...: print "Final destination:"
...: print response.status_code, response.url
...: else:
...: print "Request was not redirected"
...:
Request was not redirected
状态码也是200。response.history
什么都没有。response.url
给出了第一个url,而不是真正的url。但在firefox->开发者工具->网络中可以获得真实的url。如何在Python2.7中生成?提前谢谢!!在
您可以使用BeautifulSoup来读取HTML页面标题中的meta标记并获得重定向URL
此URL将相对于原始URL的域,使新URL
^{pr2}$http://www.vbb.de/de/download/GTFS_VBB_Nov2015_Dez2016.zip
。下载此文件会为我下载ZIP文件:在此重定向中,返回301状态:
首先需要通过解析第一个返回的HTML中的新的
window.location.href
来手动执行重定向。然后创建一个301
回复,其中包含返回的Location
头中包含的目标文件的名称:这将显示:
^{pr2}$并生成一个29464299字节的zip文件。在
相关问题 更多 >
编程相关推荐