PDA

View Full Version : [Python] Main Shop AB - Send Haggle POST Data?



Neoquest
03-11-2012, 05:58 PM
For the past few days I've been writing a MSAB, and it's nearly done. (OCR, formatting haggle, getting to haggle page, all done.) But when I try to actually send the POST data on the haggle page, it just stays on the haggle page. An example of my code:



page = "[Only registered and activated users can see links]" + str(X) + "&y=" + str(Y) + "&current_offer=" + str(price)
link = "[Only registered and activated users can see links]"
req = urllib2.Request(page)
req.add_header('Referer', link)
buying = opener.open(req).read()
print buying


The first link is just OCR and the price. The variable "link" is where I think I'm doing something wrong. (Setting the referrer) Note that link is scraped from the mainshop page when the item restocks, and it isn't always that. The resulting page source ("buying") doesn't even say that I failed to click the pet correctly, or that my haggle was rejected, it is equivalent to a refresh of the page.

Miguel
03-11-2012, 06:07 PM
It appears from the code I see you are trying to use a GET request, not a POST request.

[Only registered and activated users can see links].Request


urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable])

urllib2 works in this way: if there is no data parameter, send it as a GET request. If there is a data parameter, sent a POST request. I'd also make sure you're setting the user-agent in the headers to FF or something, since the default user-agent is Python-Urllib (or something similiar), which is obviously not a browser.

Neoquest
03-11-2012, 06:26 PM
It appears from the code I see you are trying to use a GET request, not a POST request.

[Only registered and activated users can see links].Request


urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable])

urllib2 works in this way: if there is no data parameter, send it as a GET request. If there is a data parameter, sent a POST request. I'd also make sure you're setting the user-agent in the headers to FF or something, since the default user-agent is Python-Urllib (or something similiar), which is obviously not a browser.

Don't worry, the headers are set to FF, and thanks, I'll try adding in the data.

---------- Post added at 06:26 PM ---------- Previous post was at 06:10 PM ----------

That worked! Thanks a ton!