Introductory tags: python | python-3.x | url | parameters | urlopen
Used language: Python 3.x
Used modules: urlopen | urllib.request
Status: Not yet resolved
Description of the problem:
I have url:
http://mapy.cz/#mm=TTtP@x=133054720@y=135947904@z=13
and it redirects me (in web browser) to another url:
https://mapy.cz/zakladni?x=14.412346408814274&y=50.08612581835152&z=13
I want to get the parameters x and y from the path.
x = 14.412346408814274
y = 50.08612581835152
(Geographic coordinates in decimal degrees.)
When I use:
from urllib.request import urlopen
url = "http://mapy.cz/#mm=TTtP@x=133168128@y=133141248@z=13"
print(urlopen(url).url)
It will return me:
https://mapy.cz/
When I use:
with urlopen(url) as conn:
newUrl = conn.geturl()
print (newUrl)
It will return me:
https://mapy.cz/
When I use:
with urlopen(url) as conn:
print (conn.info())
It will return me:
Server: nginx
Date: Sun, 03 Jun 2018 23:24:31 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Cache-Control: max-age=0
Expires: Sun, 03 Jun 2018 23:24:31 GMT
Strict-Transport-Security: max-age=31536000
When I use:
with urlopen(url) as conn:
print (conn.__dict__)
It will return me:
{'fp': <_io.BufferedReader name=1404>, 'debuglevel': 0, '_method': 'GET', 'headers': <http.client.HTTPMessage object at 0x000000000DD48518>, 'msg': 'OK', 'version': 11, 'status': 200, 'reason': 'OK', 'chunked': True, 'chunk_left': None, 'length': None, 'will_close': True, 'code': 200, 'url': 'https://mapy.cz/'}
There is no mention of the parameters/path behind the slash. Neither the original url nor the following url.
When I use code from What is the quickest way to HTTP GET in Python?:
import urllib.request
contents = urllib.request.urlopen("url").read()
It will return me:
'raw html...'
I don't want to open/download the html and mining those parameters from html.