Discussion about this post

User's avatar
Bijal's avatar

Hi All,

I have implemented the basic web scrapper.

Please let me know if there are any suggestions.

#################################

import requests

from bs4 import BeautifulSoup

url = "https://books.toscrape.com"

response = requests.get(url, timeout=5)

print(response.status_code)

page_content = response.content

soup = BeautifulSoup(page_content, "html.parser")

all_products=soup.find_all("article", class_="product_pod")

for product in all_products[0:3]:

title=product.find("h3").find("a")["title"]

print(f"Title: {title}")

price=product.find("p", class_="price_color").get_text()

print(f"Price: {price}")

availability=product.find("p", class_="instock availability").get_text(strip=True)

print(f"Stock: {availability}\n")

#################################

Thanks

No posts

Ready for more?