Results 1 to 3 of 3

Thread: [Python] Main Shop AB - Send Haggle POST Data?

  1. #1

    Joined
    Jan 2012
    Posts
    96
    Userbars
    1
    Thanks
    4
    Thanked
    10/8
    DL/UL
    26/0
    Mentioned
    16 times
    Time Online
    8h 17m
    Avg. Time Online
    N/A

    [Python] Main Shop AB - Send Haggle POST Data?

    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:

    Code:
    page = "http://www.neopets.com/haggle.phtml?x=" + str(X) + "&y=" + str(Y) + "&current_offer=" + str(price)
    link = "http://www.neopets.com/haggle.phtml?obj_info_id=8669&stock_id=722720051&brr=1366"
    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.

  2. #2

    Joined
    Dec 2011
    Posts
    488
    Thanks
    303
    Thanked
    559/263
    DL/UL
    13/4
    Mentioned
    34 times
    Time Online
    1h 58m
    Avg. Time Online
    N/A
    It appears from the code I see you are trying to use a GET request, not a POST request.

    (you need an account to see links)

    Code:
    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.

  3. The Following User Says Thank You to Miguel For This Useful Post:

    Neoquest (03-11-2012)

  4. #3

    Joined
    Jan 2012
    Posts
    96
    Userbars
    1
    Thanks
    4
    Thanked
    10/8
    DL/UL
    26/0
    Mentioned
    16 times
    Time Online
    8h 17m
    Avg. Time Online
    N/A
    Quote Originally Posted by ./m View Post
    It appears from the code I see you are trying to use a GET request, not a POST request.

    (you need an account to see links)

    Code:
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •