Hi community :)
I am a bit stuck with my project. I try to scrape the news from the websites https://mercomindia.com/category/solar/?_page=1 and https://www.pv-magazine.com/news/page/2/ with BeautifulSoup.
BS4 is working correctly, I used my code already for multiple other websites but in these two cases (especially pv-magazine is very valuable to me), I do not find any html-tags. I use the find_all to find the date tags and a href tags but my lists are always empty. I tried to change it from html5lib to htmlparser, tried to change the tags but nothing seems to work. Anyone got a clue, what's wrong?
Here's my code:
dates = []
news_bodies = []
# Capture the news from this url
scrape_url = 'https://mercomindia.com/category/solar/?_page=1'
# Parsing the HTML
r1 = requests.get(scrape_url)
page = r1.content
# Using Beatifulsoup to get the content of the correct HTML attributes
page_soup = soup(page, 'html.parser')
dates_soup = page_soup.find_all('span',{'class':'entry-date'})
titles_soup = page_soup.find_all('a',{'class':'_self cvplbd'})
for i in range (0, len(dates_soup)):
corpus = ""
time.sleep(.1) # Prevents site spam
dates.append(dates_soup[i].time['text'])
news_url = titles_soup[i]['href']
r2 = requests.get(news_url)
news_page = r2.content
news_page_soup = soup(news_page, 'html.parser')
news_text = news_page_soup.find_all('p')
for news in news_text:
if (("<!--" in news.text) == False):
text_p_tag = news.text.replace("\n", " ").replace("\t", " ")
if (("staff reporter" in text_p_tag) == True):
break
corpus += text_p_tag
news_bodies.append(corpus)