python - What is the trick in this website? -


i can access webpage in firefox browser: http://www.ip-adress.com/ip_tracer/74.82.190.99 can information ip.

however, when fetch using python, there errors:

import urllib f = urllib.urlopen("http://www.ip-adress.com/ip_tracer/74.82.190.99") print f.read() 

i error:

<!doctype html public "-//ietf//dtd html 2.0//en"> <html><head> <title>403 forbidden</title> </head><body> <h1>forbidden</h1> <p>you don't have permission access /ip_tracer/74.82.190.99 on server.</p> </body></html> 

i take page's source code:

<form action="/ip_tracer/" method="post"> <div> <input id="ipqry" name="qry" type="text" value="74.82.190.99" size="18" maxlength="255" onclick="cleanup(this)"> <input type="submit" value="track ip, host or website" onclick="progress(true)"> </div> </form> 

and use post method, result same:

import urllib  params = urllib.urlencode({'qry': '74.82.190.99'})  f = urllib.urlopen("http://www.ip-adress.com/ip_tracer/", params)  print f.read() 

the result same 403 forbidden.

can give me hint? using python 2.5 on windows xp.

thanks lot!

probably server reads user-agent header , decides not serve request. alternatively can rely on other headers being typically set normal browsers (like ff).

i tried one:

import urllib2  request = urllib2.request("http://www.ip-adress.com/ip_tracer/74.82.190.99") request.add_header("user-agent", "mozilla/5.0 (windows; u; windows nt 5.1; es-es; rv:1.9.1.5) gecko/20091102 firefox/3.5.5")  f = urllib2.urlopen(request) print f.read() 

and got proper result.

note: please check terms of service of site if plan use programmatically. might violate rules if keep sending such requests automatically.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -