简体   繁体   中英

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)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM