I’m trying to Scrape a blog “https://blog.feedspot.com/ai_rss_feeds/” and crawl through all the links in it to look for Artificial Intelligence related information in each of the crawled links.
The blog follows a pattern – It has multiple RSS Feeds and each Feed has an attribute called “Site” in the UI. I need to get all the links in the “Site” attribute. Example : aitrends.com, sciecedaily.com/… etc. In the code, the main div has a class called “rss-block”, which has another nested class called “data” and each data has several
tags and the
tags have in them. The value in href gives the links to be crawled upon. We need to look for AI related articles in each of those links found by scraping the above-mentioned structure.
I’ve tried various variations of the following code but nothing seemed to help much.
import requests
from bs4 import BeautifulSoup
page = requests.get('https://blog.feedspot.com/ai_rss_feeds/')
soup = BeautifulSoup(page.text, 'html.parser')
class_name='data'
dataSoup = soup.find(class_=class_name)
print(dataSoup)
artist_name_list_items = dataSoup.find('a', href=True)
print(artist_name_list_items)
I’m struggling to even get the links in that page, let alone craling through each of these links to scrape articles related to AI in them.
If you could help me finish both the parts of the problem, that’d be a great learning for me. Please refer to the source of https://blog.feedspot.com/ai_rss_feeds/ for the HTML Structure. Thanks in advance!
2
Answers
The first twenty results are stored in the html as you see on page. The others are pulled from a script tag and you can regex them out to create the full list of 67. Then loop that list and issue requests to those for further info. I offer a choice of two different selectors for the initial list population (the second – commented out – uses
:contains
– available with bs4 4.7.1+)To get all the sublinks for each block, you can use
soup.find_all
:Output: