I am trying to scrape some information from a website using BeautifulSoup and I am having huge trouble with it. I have been searching and trying to figure this out for hours now and I cannot figure it out. I am trying to scrape the title of the company from (https://www.duckduckgo.com/privacy) written with the bold red text along with the number of offers (the number at the bottom of the description). I am aware that the code is currently only looking for the "h2" and not for the paragraph and I am also aware that the exact match is a hyperlink "a" but I couldn't find a solution for searching multiple classes at once in one tag because the original classes for the hyperlink are "class="link ng-binding"" and I don't know how to reference to multiple of them at once so I am trying to point out to the single class "h2" title which contains the hyperlink itself inside of it. This is the code that I am having trouble with :
from urllib.request import urlopen
from bs4 import BeautifulSoup
# Scrape company names, offers
toScrape = "https://www.duckduckgo.com/privacy"
requestPage = urlopen(toScrape)
pageHTML = requestPage.read()
requestPage.close()
HTMLSoup = BeautifulSoup(pageHTML, 'html.parser')
scrapedItems = HTMLSoup.find_all('h2')
CSVExport = 'ConectHeader.csv'
save = open(CSVExport, 'w')
CSVHeaders = 'Price, stock\n'
for item in scrapedItems:
company = item.find('h2', class_="title").text
offers = item.find('p', class_="estates-cnt").text
save.write(company + '' + stock)
I don't get any errors or even warning in my IDE. The process finishes with exit code 0 but when I open the final .csv file it doesn't contain any information what so ever. I cannot figure out why doesn't the output get saved into the csv file. I have also tried running it through print and print returned "[]" which probably means that the problem is not directly caused by the data being saved into the csv file. Thanks for anyone for any help with this I am tearing my hair off right now because of this!