sergey-dolzhkin
sergey-dolzhkin

Reputation: 29

Performing a get request in Python

Please tell me why this similar lists of code get different results. First one (yandex.ru) get page of request, and another one get Main page of site (moyareklama.ru)

import urllib

base = "http://www.moyareklama.ru/single_ad_new.php?"
data = {"id":"201623465"}
url = base + urllib.urlencode(data)
print url
page = urllib.urlopen(url).read()
f = open ("1.html", "w")
f.write(page)
f.close()
print page

##base = "http://yandex.ru/yandsearch?"
##data = (("text","python"),("lr","192"))
##url = base + urllib.urlencode(data)
##print url
##page = urllib.urlopen(url).read()
##f = open ("1.html", "w")
##f.write(page)
##f.close()
##print page

Upvotes: 2

Views: 239

Answers (1)

marklap
marklap

Reputation: 481

Most likely the reason you get something different with urllib.urlopen and your browser is because your browser can be redirected with javascript and meta/refresh tags as well as standard HTTP 301/302 responses. I'm pretty sure the urllib module will only be redirected by HTTP 301/302 responses.

Upvotes: 2

Related Questions