1

I am very new to web scraping. I read about BeautifulSoup and tried to use it. But I am not able to extract text with given class name "company-desc-and-sort-container". I am not even able to extract the title from html page. This is the code which I tried:

from BeautifulSoup import BeautifulSoup
import requests

url= 'http://fortune.com/best-companies/'    
r = requests.get(url)

soup = BeautifulSoup(r.text)

#print soup.prettify()[0:1000]
print soup.find_all("title")

letters = soup.find_all("div", class_="company-desc-and-sort-container")

I am getting the following error:

 print soup.find_all("title")
TypeError: 'NoneType' object is not callable
1
  • 1
    what's your beautifulsoup version? Commented Dec 20, 2016 at 14:22

2 Answers 2

1

You are using BeautifulSoup version 3, which is not only maintained anymore, but also does not have the find_all() method. And, since the dot notation is used as a shortcut to find(), BeautifulSoup tries to find element with "find_all" tag name which results into None. Then, it would execute None("title") which results into:

TypeError: 'NoneType' object is not callable

Upgrade to BeautifulSoup version 4, replace:

from BeautifulSoup import BeautifulSoup

with:

from bs4 import BeautifulSoup

Make sure to have beautifulsoup4 package installed:

pip install --upgrade beautifulsoup4
Sign up to request clarification or add additional context in comments.

Comments

0
soup.find_all("title")

Is not finding a title tag and returning "none". Also the "find_all" method will return a list if it does find something and you will get a different error. You can't print a list. Use just the "find" method. That will do d the first title tag.

Then does the html page even have a title tag? Search, and only print if not none.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.