Tell me, comrades, why seemingly identical code fragments behave differently. Is the search page on the yandex site opened and saved to a file, and the main page on the moyareklama site?

import urllib base = "" 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 = "" ##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 

Cookie doesn't work either ...

 import requests url = "" r = requests.get(url) cookies = r.cookies payload = {"id":"201686924"} url = "" s = requests.get(url, params = payload, cookies = cookies) print cookies print s.url ##print s.text 
  • decided the question - sergey-dolzhkin
  • Then tell me how and close the question =) - rnd_d
  • 2
    You were right about cookies, but you need to take them not from the main page, but from the page with the name of the city ( ), since the parameter containing the index of the city is sent to cookies. After that, everything starts to work :) - sergey-dolzhkin

2 answers 2

It will only let you go there if you have cookies, accept them first and then you can give them to this page in the request to receive them.

  • with the cookie also does not work .. - sergey-dolzhkin

So this resource is arranged. Try it through the browser or by curl. He always returns at the beginning of the main. I suspect he needs a session first.