Pythonista
Pythonista

Reputation: 11645

Submitting advanced ebay searches with Python

I know there's an API among other things for scraping ebay but all I need is to submit advanced searches.

So, I made a function to do this, (hardcoded for now) but there's one thing I cannot get to work. It's marking items as new.

From inspecting the element on their form when items are marked as New in the advanced search form the other two fields get marked as disabled and that's the only changes I could see.

I'm submitting the form as below and writing the content to a file so I can open it up to see the result.

Everything works fine and I can open the webpage and it's the correct results, but the New option is not selected.

What is the correct way to submit this selection? I've tried lots of variations and nothing I've tried works.

def submit_advanced_search():

    params = {
        '_nkw': "",
        '_in_kw': 1,
        '_ex_kw': "",
        '_sacat': 20081,
        'LH_Sold': 1,
        '_udlo': 20,
        '_udhi': 250,
        'LH_ItemConditionUsed': {'disabled':'disabled'},
        'LH_ItemConditionNS': {'disabled':'disabled'},
        'LH_BIN': 1,
        'LH_FS': 1,
        'LH_Complete': 1,
    }

    content = requests.get("http://www.ebay.com/sch/i.html", params = params).content
    with open("search_result.html", "wb") as f:
        f.write(content)

Upvotes: 1

Views: 275

Answers (1)

Pythonista
Pythonista

Reputation: 11645

Here's what worked for me. The correct field is 'LH_ItemCondition': 3.

So the function would be:

def submit_advanced_search():

    params = {
        '_nkw': "",
        '_in_kw': 1,
        '_ex_kw': "",
        '_sacat': 20081,
        'LH_Sold': 1,
        '_udlo': 20,
        '_udhi': 250,
        'LH_ItemCondition': 3,
        'LH_BIN': 1,
        'LH_FS': 1,
        'LH_Complete': 1,
    }

    content = requests.get("http://www.ebay.com/sch/i.html", params = params).content
    with open("search_result.html", "wb") as f:
        f.write(content)

Upvotes: 2

Related Questions