I am scraping an product information. But I scrape its price it doesn’t give me proper output. There is no error but not the desired output.
And also it produce error while finding the category of a product.
Here is my code.
import requests
from bs4 import BeautifulSoup as bs
import pandas
url='https://shop.eziline.com/product/uncategorized/umrah-management-system/'
r=requests.get(url)
soup=bs(r.content,'html.parser')
name=soup.find(class_='product_title entry-title').text.strip()
print(name)
price=soup.find('span',class_='woocommerce-Price-amount amount').text.strip()
print(price)
detail=soup.find(class_='woo-product-details_short-description').text.strip()
print(detail)
category=soup.find('cats-link a').text.strip()
print(category)
2
Answers
The attributes you are using in the
find
method apply to more than one tag, you can view all the tags usingfindAll
as follows:which will result in the following output
to get only the last tag which is the price you can use
You are
picking up the first price rather than the target price. Instead, you can use the main content id as an anchor to the correct section to return the price from
You are trying to use css selector syntax in the last line without applying via the appropriate method and adding in the syntax for a class selector. You could also use
category=soup.find(class_='cats-link').a.text.strip()
Instead: