Simple Web Scraping Example Using BeautifulSoup in
Simple Web Scraping Example Using BeautifulSoup in
by FuzzyPotato
In this Instructable, we'll explore the world of web scraping using the BeautifulSoup library in Python. Our focus will be
on extracting view statistics from an Instructable member's account.
Web scraping allows us to automatically gather data from websites, and with BeautifulSoup, we can easily navigate and
extract information from the HTML structure of Instructables pages.
Speci cally, we'll be retrieving the view counts from Instructables projects. By harnessing the power of web scraping, we
can track project popularity, monitor growth, and gain valuable insights into the reach and impact of di erent creations.
With just a few lines of code, we'll unlock the ability to collect and analyze data from Instructables projects, opening up a
world of possibilities for research, analysis, and tracking. Let's dive in and discover the exciting world of web scraping
with BeautifulSoup and Instructables statistics!
Supplies:
Simple Web Scraping Example Using BeautifulSoup: Instructable Statistics With Python: Page 1
Step 1: Install Required Libraries
Step 2: Code
Now that we have the beautifulsoup4 and requests libraries installed, it's time to write the Python code that will allow us
to scrap the instructable values.
Simple Web Scraping Example Using BeautifulSoup: Instructable Statistics With Python: Page 2
import requests
from bs4 import BeautifulSoup
response = requests.get(account_url)
soup = BeautifulSoup(response.text, "html.parser")
instructables = soup.find_all("div", class_="thumbnail ible-thumbnail")
response = requests.get(project_url)
soup = BeautifulSoup(response.content, 'html.parser')
view_count_element = soup.find('p', class_='svg-views view-count')
view_count = int(view_count_element.text.strip().replace(',', ''))
print(f"Title: {title}")
print(f"URL: {project_url}")
print(f"View Count: {view_count}")
print("-------------------------")
In the nal step, we will run the code to scrape and display the view statistics from an Instructables member's projects.
Here is how it will work:
1. The code will start by opening the member's project page.
2. Using BeautifulSoup, the code will navigate the HTML content and collect all the project titles.
3. The code will then open each project page and extract the view count for each project.
4. The view count for each project will be extracted.
5. The code will display the extracted statistics to the user.
6. If the view count element is not found, a message indicating its unavailability will be displayed.
By following these steps, you will successfully scrape and display the view statistics from an Instructables member's
projects.
Feel free to expand on this code and explore more advanced scraping techniques or integrate it into your own projects.
happy tinkering!
Step 4:
Simple Web Scraping Example Using BeautifulSoup: Instructable Statistics With Python: Page 3
Simple Web Scraping Example Using BeautifulSoup: Instructable Statistics With Python: Page 4