-2

I have an eBay page in which I would like to formulate a list of all the item numbers on that page. I have executed and parsed the HTML content using requests and Beautiful Soup, but I can't figure out how to get exactly what I need.

<li id=β€œitem247f10fa70” class=β€œs-card s-cardβ€”horizontal: data-viewport=β€œβ€{β€œtrackableId”:”01K1XBEX0ATN4B5KW20VVB90ZN”}” data-view=β€œmi:1686|iid:3” data-listingid=β€œ156760641776”>

But I am just trying to single out the number 156760641776.

3
  • Please post the tag as text, not an image of text. And what "variations" did you try? Commented Aug 5 at 14:34
  • My apologies, I am new to this website. The actual html tags look like this: <li id=β€œitem247f10fa70” class=β€œs-card s-cardβ€”horizontal: data-viewport=β€œβ€{β€œtrackableId”:”01K1XBEX0ATN4B5KW20VVB90ZN”}” data-view=β€œmi:1686|iid:3” data-listingid=β€œ156760641776”> Commented Aug 5 at 14:57
  • If you post what you tried, and how it came up short, someone might be able to help you fix it. Commented Aug 5 at 15:21

1 Answer 1

1

Without the full code you are working with, can only give a general solution here.

First you want to get all the elements with that <li> tag. Note this, without an additional identifiers or attributes, will grab any and all list tags.

They from that list, pull out the 'data-listingid' attribute.

from bs4 import BeautifulSoup

html = '''<li id="item247f10fa70" class="s-card s-cardβ€”horizontal: data-viewport=""{"trackableId":"01K1XBEX0ATN4B5KW20VVB90ZN"}" data-view="mi:1686|iid:3" data-listingid="156760641776">'''
soup = BeautifulSoup(html, 'html.parser')

list_items = soup.find_all('li')

for each in list_items:
    data_id = each.get('data-listingid')
    print(data_id)

Output:

Out[18]: '156760641776'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.