python - Useragent showing 302 in code on browser it gives result -
i trying page result search on google. target amp results in page. tried android kitkat user-agent in browser results in listing amp pages in search result. trying search same keyword same user agent using socket methods in python gives 302 status code.
user-agent : mozilla/5.0 (linux; android 4.4.2; nexus 4 build/kot49h) applewebkit/537.36 (khtml, gecko) chrome/34.0.1847.114 mobile safari/537.36
if see bottom of page shows amp page result axisbank , can see user agent. when try replace code user agent same gives me 302. if use useragent results listed not amp pages.
self.opened_url = self.buildurl() print self.opened_url html="" s = socket.socket(socket.af_inet, socket.sock_stream) s.setsockopt(socket.sol_socket, socket.so_reuseaddr, 1) s.setsockopt(socket.sol_socket, 25 , "eth0") s.connect((self.domain, 80)) request = b"get " +self.opened_url +" http/1.1\nhost: " + self.domain + "\nuser-agent:" + useragent + "\naccept-encoding: gzip, deflate\nconnection: close \naccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n\n" try: s.send(request) content="" while (true): result = s.recv(1024) if len(result) == 0 : break content = content + result s.close() data = content.split('\r\n\r\n') code = int(data[0][9:12]) print code if code == 301 or code == 302 or code == 403 or code == 503: print "captcha found" print "content" print content self.has_captcha = true return ""
this code works , gives result use agents not list amp results. want amp page in search results. help
Comments
Post a Comment