Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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使用urllib打开url,然后返回已打开网页的更改url_Python_Url_Urllib2 - Fatal编程技术网

Python使用urllib打开url,然后返回已打开网页的更改url

Python使用urllib打开url,然后返回已打开网页的更改url,python,url,urllib2,Python,Url,Urllib2,我想向谷歌地图发送一些请求。我打开根据请求更改的url。我想找回更改过的url。 例如: import urllib, urllib2 my_address = '1600 Amphitheatre Parkway Mountain View, CA 94043' data = urllib.urlencode({'output':'csv', 'q':my_address}) req = urllib2.Request('https://www.google.co.uk/maps/place

我想向谷歌地图发送一些请求。我打开根据请求更改的url。我想找回更改过的url。 例如:

import urllib, urllib2

my_address = '1600 Amphitheatre Parkway Mountain View, CA 94043'
data = urllib.urlencode({'output':'csv', 'q':my_address})
req = urllib2.Request('https://www.google.co.uk/maps/place?' + data)
res_0 = urllib2.urlopen(req)
print res_0.geturl()
要打开的url(
res\u 0.geturl()
):

'https://www.google.co.uk/maps/search/1600+圆形剧场+公园道+山景+景观,+CA+94043/数据=!4m2!2m1!4b1?dg=dbrw和newdg=1'

我想找回更改后的url,即:

'https://www.google.co.uk/maps/place/1600+圆形剧场+Pkwy,+Mountain+View,+CA+94043,+USA/@37.4223371,-122.0866079,17z/数据=!3m1!4b1!4m5!3m4!1s0x808fba027820e5d9:0x60a90600ff6e7e6e!8m2!3d37.4223329!4d-122.0844192'

我在浏览器中手动打开了
resu 0
url,得到了上面更改的url

我该怎么做

谢谢大家!

您可以在urllib2中使用.geturl()方法

例如:

print res_0.geturl()
可以在urllib2中使用.geturl()方法

例如:

print res_0.geturl()

很抱歉,我的示例中遗漏了这一点(我更新了我的问题)。因此
res_0.geturl()
返回“url to open”。或者这会返回我想要的url吗?对不起,我在示例中错过了这个(我更新了我的问题)。因此
res_0.geturl()
返回“url to open”。或者这会返回我想要的url吗?