Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using BeutifulSoups find() but getting pythons find() instead

I am learning web scraping and I’ve run into a problem. I am trying to use the .find() method built into BS4 but it is seeing the code as Pythons built in .find()

I am not sure how to fix it. I have tried using .soup.find() but it didn’t seem to fix it either.

Here is my code, I am getting the error on line 9 and 10

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from bs4 import BeautifulSoup
import requests

html_text = requests.get('https://www.diyelectronics.co.za/store/353-printers')
soup = BeautifulSoup(html_text.text, 'lxml')

printers = soup.find('ul', class_='product_list grid row')
for printer in printers:
    printer_price = printer.find('span', class_='price product-price')
    printer_name = printer.find('h5', class_='product-name-container')

    print(f'''
    Printer Name: {printer_name}
    Printer Price: {printer_price}
    ''')

>Solution :

If there are multiple <ul> elements with class of product_list grid row, you should use .find_all() instead of .find():

printers = soup.find_all('ul', class_='product_list grid row')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading