Search code examples
python-3.xweb-scrapingbeautifulsoup

Scraping specific attribute in tr tag


allId=soup.find_all("tr","data-id")

HTML Code

I just take data-id's values. How can I scrape these tags?


Solution

  • To fetch value of data-id try this.

    allId=soup.find_all("tr",attrs={"data-id" : True})
    for item in allId:
        print(item['data-id'])
    

    You can also use css selector.

    allId=soup.select("tr[data-id]")
    for item in allId:
        print(item['data-id'])