⚠️ Malware / Trojaner / VirenJSCeal Malware Can Bypass Google Authentication Using Stolen Session Cookies(07.09.2026 um 09:53 Uhr)
⚠️ Malware / Trojaner / VirenJSCeal Malware Can Bypass Google Authentication Using Stolen Session Cookies(07.09.2026 um 09:53 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 8 Min Lesezeit
0

How to Scrape Data From Goodreads Using Python and BeautifulSoup

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Web scraping is a powerful tool for gathering data from websites. Whether you’re collecting product reviews, tracking prices, or, in our case, scraping Goodreads books, web scraping provides endless opportunities for data-driven applications.



In this blog post, we’ll explore the fundamentals of web scraping, the power of the Python BeautifulSoup library, and break down a Python script designed to scrape Goodreads Choice Awards data. Finally, we’ll discuss how to store this data in a CSV file for further analysis or applications.






What is Goodreads?



Goodreads is the world’s largest platform for readers and book recommendations. It provides users with access to book reviews, author details, and popular rankings. Every year, Goodreads hosts the Goodreads Choice Awards, where readers vote for their favorite books across various genres like fiction, fantasy, romance, and more. This makes Goodreads an ideal target for web scraping to gather insights about trending books and authors.








What is Web Scraping?



Web scraping involves extracting data from websites in an automated manner. It allows you to collect and structure information for tasks such as:




  • Analyzing trends and patterns.

  • Aggregating content like reviews or articles.

  • Feeding machine learning models or databases.








Setting Up Your Environment



Before diving into the script, you need to install the necessary libraries.





  1. Install Python



    Make sure you have Python installed on your system.




  2. Install Required Libraries



    Install the required libraries using pip:



    CODE
    pip install beautifulsoup4
    pip install requests




    request: Allows us to send HTTP requests to a URL and retrieve the web page’s content.



    BeautifulSoup: Simplifies HTML parsing and data extraction.








Once these installations are complete, you're ready to scraping!








Introduction to BeautifulSoup



BeautifulSoup is a Python library for parsing HTML and XML documents. It enables developers to navigate page structures, extract content, and transform raw HTML into a structured format.



Key Methods in BeautifulSoup



Here are a few essential methods that we will be using in our script:




  • BeautifulSoup(html, 'html.parser'): Initializes the parser and allows you to work with the HTML content.

  • soup.select(selector): Finds elements using CSS selectors, such as classes or tags.

  • soup.find(class_='class_name'): Locates the first occurrence of an element with a specified class.

  • soup.find_parent(class_='class_name'): Finds the parent tag of the current element.

  • soup.get('attribute'): Retrieves the value of an attribute from an element, like href or src.



For a complete list of methods, check out the



Next, iterate through each category to get the genre name and its page URL.




CODE
for index, category in enumerate(categories):
genre = category.select('h4.category__copy')[0].text.strip()
url = category.select('a')[0].get('href')
category_url = f"{app_url}{url}"






Here, we extract the category name (genre) and the category page URL for further processing.



We will send another request to each category_url and locate all the books under that category.




CODE
res = requests.get(category_url, headers=HEADERS)
soup = bs(res.text, 'html.parser')

category_books = soup.select('.resultShown a.pollAnswer__bookLink')






category_books will contain the list of all the books under the respective category.






Extracting Book Data



Once we have the list of books, we will be iterating over each books and extract the data.



Extract Votes




CODE
for book_index, book in enumerate(category_books):
parent_tag = book.find_parent(class_='resultShown')
votes = parent_tag.find(class_='result').text.strip()
book_votes = clean_string(votes).split(" ")[0].replace(",", "")






If we see in the DOM, voting count is present in the parent element of the category element. So we need to use find_parent method to locate the element and extract the voting count.





You can define this function at the top of the script.




CODE
def get_ratings_reviews(text):
# Find the substring for ratings
ratings = text[:text.find(" ratings")].replace(",", "")

# Find the substring for reviews
reviews = text[text.find("and ") + 4:text.find(" reviews")].replace(",", "")

return int(ratings), int(reviews)






By navigating to each book’s details page, additional information like ratings, reviews, and detailed descriptions is extracted. Here, we are also checking if book description element exists otherwise putting a default description so that the script does not fails.




CODE
author_avatar_url_element = soup.select('.PageSection .AuthorPreview a.Avatar img.Avatar__image')
if author_avatar_url_element:
author_avatar_url = author_avatar_url_element[0].get('src')
else:
author_avatar_url = 'No Avatar found'

author_description_element = soup.select('.PageSection > .TruncatedContent .Formatted')
if author_description_element:
author_description = author_description_element[0].text
else:
author_description = 'No description found'

print(author_description)

bookPages = soup.select_one(".FeaturedDetails p[data-testid='pagesFormat']")
if bookPages:
pages_format = bookPages.text[:bookPages.text.find(" pages")]
else:
pages_format = "No pages found"
print(pages_format)

publication_info = soup.select_one(".FeaturedDetails p[data-testid='publicationInfo']")
if publication_info:
publication = publication_info.text[16:]
else:
publication = "No publication found"
print(publication)






Here, we have also gathered author details, publication information and other metadata.



Create a Book Dictionary



Let's store all the data we have extracted for a book in a dictionary.




CODE
book_dict = {
"category": genre,
"votes": book_votes,
"title": book_name,
"description": book_description,
"author_name": book_author,
"author_about": author_description,
"avatar_url": author_avatar_url,
"pages": pages_format,
"rating": book_rating,
"ratings": book_ratings,
"reviews": book_reviews,
"publication_info": publication,
"img_url": book_img_url,
"book_url": f"{app_url}{book_url}"
}






We will use this dictionary to add the data in a csv file.








Storing Data in a CSV File



We will use the csv module which is a part of Python's standard library. So you don't need to install it separately.



First we need to check if this is the first entry. This check is required to add the header in the csv file in the first row.




CODE
csv_filename = "books.csv"

if index == 0 and book_index == 0:
with open(csv_filename, "w", newline="", encoding="utf-8") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=book_dict.keys())
writer.writeheader()






We are using mode="w" which will create a new csv file with the header entry.



Now for all subsequent entries, we will append the data to the CSV file:




CODE
with open(csv_filename, mode="a", newline="", encoding="utf-8") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=book_dict.keys())
writer.writerow(book_dict)






mode="a" will append the data to CSV file.



Now, sit back, relax, and enjoy a cup of coffee ☕️ while the script runs.



Once it’s done, the final data will look like this:



.








Summary



We have learned how to scrape Goodreads data using Python and BeautifulSoup. Starting from basic setup to storing data in a CSV file, we explored every aspect of the scraping process. The scraped data can be used for:




  • Data visualization (e.g., most popular genres or authors).

  • Machine learning models to predict book popularity.

  • Building personal book recommendation systems.



Web scraping opens up possibilities for creative data analysis and applications. With libraries like BeautifulSoup, even complex scraping tasks become manageable. Just remember to follow ethical practices and respect the website’s terms of service while scraping!

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Anzeige: Dual-USB-SD-Kartenleser von Acer für unter 8 Euro bei Amazon
1 Quelle
Hypertune: Kostenpflichtige Software will Gaming-PC optimieren
1 Quelle
KI-Korrekturhilfe für die Schule: Lerne schreiben wie ein Chatbot
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Scrape Data From Goodreads Using Python and BeautifulSoup

Thematisch verwandte Begriffe: Scrape, Data, From, Goodreads · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...