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
>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"})