I'm having some trouble trying to write a basic webscraper for a Minecraft server site. I'm pretty new to python (but fluent in C/java/.net) and can't seem to get the damn thing to work.
I'm trying to reach
amishsmp.net/player.php?playerName=Leth
The following code works to the extent of successfully reaching and scraping from the site. But the page returned is an error saying no playerName was provided. So there must be something wrong with the param not being appended correctly?
I've tried as much as I can to fix it. Any suggestions?
import httplib, urllib
params = urllib.urlencode({'playerName':'Leth'})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("amishsmp.net")
conn.request("GET", "/player.php", params, headers)
response = conn.getresponse()
print response.status, response.reason
print "####################"
data = response.read()
print data
conn.close()
EDIT: Doing this wihtout using the params does actually work...but i dont feel like thats the way it should be done:
conn.request("GET", "/player.php?playerName=Leth")