I'm trying to send GET
request to some urls with User-Agent
as mobile to get the the redirected url (for example - http://m.google.com instead of http://google.com).
I've tried requests
library and urllib2
too - it seems that the User-Agent
isn't sent with the request. Also read another questions here but the answers was not clear enough - if its just buggy or I miss something?
This is my code:
try:
req = requests.get(item.url, headers={'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B137 Safari/601.1'}, timeout=5)
except requests.exceptions.HTTPError:
continue
except requests.exceptions.Timeout:
continue
print (item.url + ' => ' + req.url + ' (' + str(req.status_code) + ')')
Still, always get the computer version instead of mobile version.