Python BeautifulSoup check if find returns Null object

0 votes

Hi. I am new to python web scraping. I am trying to scrape a website and store data. The data I am trying to extract is under the item-name class and between the anchor tags. I did a little research and found a code that I could use.


The problem is that in some case, there is no Object for this class. So it the script is showing an error telling the object in NoneType.

So, I want to build a logic where my script checks if the value returned is Null and extract the data only if the value is not Null.

How can I do this?

May 9 in Python by Shaan

1 answer to this question.

0 votes

You can add an if condition to check and then extract the date if there is any value returned. Something like this:

if (name=page.find('a',{'class':'item-name'}):
answered May 9 by Ruby

Related Questions In Python

+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 56,920 points
0 votes
1 answer

Python Null Object

Use the 'None' keyword to denote the ...READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
0 votes
1 answer

How to find if setuptools is installed in python?

You can use python interpreter to check ...READ MORE

answered Jan 29 in Python by Omkar
• 67,660 points
0 votes
1 answer

How do I check if input string is a valid regular expression or not in Python?

Hi. Good question! Well, just like what ...READ MORE

answered Feb 12 in Python by Nymeria
• 3,520 points
0 votes
1 answer

How to parse html file to BeautifulSoup?

Hey. Refer to the following code: driver.get("link") html = ...READ MORE

answered Apr 2 in Python by Kirti
0 votes
1 answer

GAE: python code to check if i'm on dev_appserver or deployed to appspot

I don't know if you still need ...READ MORE

answered Sep 10, 2018 in Python by anonymous
0 votes
1 answer

How to check if a substring is present in a string using Python?

To check if the substring exists in ...READ MORE

answered May 9 in Python by Sharan