Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I find all the occurence of a specific tag in a HTML file

It’s my first time scraping a website

In a big HTML file, I’m trying to return everything that has a specific tag (like this : "span data-qa-id="aditem_price"") with BeautifulSoup
But I can’t find an answer, someone knows how to do it ?
I’m trying to learn a little bit about scraping

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the find_all method: (As mentioned in the document, the first param is the tag name, the second param is an object of attributes)

sample_web_page = 'your_url'
page = requests.get(sample_web_page)
soup = BeautifulSoup(page.content, "html.parser")

results = soup.find_all("span", {"data-qa-id" : "aditem_price"})

If you’re reading from file, you can pass a file object to it:

with open("your_file_path") as fp:
    soup = BeautifulSoup(fp, 'html.parser')
    results = soup.find_all("span", {"data-qa-id" : "aditem_price"})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading