dimanche 28 mars 2021

How to extract text from an HTML div tag file with BeautifulSoup?

My python code is as below:


import requests 
from bs4 import BeautifulSoup
flipurl = "https://www.flipkart.com/search?q=realme+7&otracker=search&otracker1=search&marketplace=FLIPKART&as-show=off&as=off"
r = requests.get(flipurl)
htmlContent = r.content
soup = BeautifulSoup(htmlContent,'html.parser')
 
#i scrap flipkart product price

price= soup.find_all("div",class_="_30jeq3 _1_WHN1")
print(price.get_text())

#**I got this error how I get text:**

  "ResultSet object has no attribute '%s'. You're probably treating a list of elements like a single element. Did you call find_all() 
when you meant to call find()?" % key
AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

As you can see from the above snippet I have tried to extract all the text but all I get an error and None. please solve this




Aucun commentaire:

Enregistrer un commentaire