Python Error: TypeError: 'NoneType' object is not callable
Python Error: TypeError: 'NoneType' object is not callable
下面是我的代码和我遇到的错误
import requests
import BeautifulSoup
from BeautifulSoup import BeautifulSoup
url = "http://www.indeed.com/jobs? q=hardware+engineer&l=San+Francisco%2C+CA"
r = requests.get(url)
soup = BeautifulSoup(r.content)
job_titles = soup.find_all("a", {"class", "jobtitle"})
print job_titles
我得到的错误:
Traceback (most recent call last):
File "webscraping.py", line 13, in <module>
job_titles = soup.find_all("a", {"class", "jobtitle"})
TypeError: 'NoneType' object is not callable
表示soup.find_all是None。确保它不是 none。此外,我在您的代码中注意到的另一件可疑的事情是 imports
import BeautifulSoup
from BeautifulSoup import BeautifulSoup
确保导入其中任何一个并相应地修改
soup = BeautifulSoup(r.content)
您使用的 BeautifulSoup 3 似乎没有 find_all
,只有 findAll
.
如果您要使用 BeautifulSoup,请使用 findAll
3.
或使用BeautifulSoup 4 to use find_all
:
from bs4 import BeautifulSoup
下面对我有用 - jobtitle
是 h2
的 class 名称而不是 a
。我和 bs4 '4.4.0'
import requests
from bs4 import BeautifulSoup
url = "http://www.indeed.com/jobs? q=hardware+engineer&l=San+Francisco%2C+CA"
r = requests.get(url)
soup = BeautifulSoup(r.content)
job_titles = soup.find_all("h2", {"class", "jobtitle"})
for job in job_titles:
print job.text.strip()
打印-
Management Associate - Access & Channel Management
Airline Customer Service Agent (Korean Speaker preferred) SF...
Event Concierge
Flight Checker
Office Automation Clerk
Administrative Assistant III
Operations Admin I - CA
Cashier Receptionist, Grade 3, (Temporary)
Receptionist/Office Assistant
Full-Time Center Associate
下面是我的代码和我遇到的错误
import requests
import BeautifulSoup
from BeautifulSoup import BeautifulSoup
url = "http://www.indeed.com/jobs? q=hardware+engineer&l=San+Francisco%2C+CA"
r = requests.get(url)
soup = BeautifulSoup(r.content)
job_titles = soup.find_all("a", {"class", "jobtitle"})
print job_titles
我得到的错误:
Traceback (most recent call last):
File "webscraping.py", line 13, in <module>
job_titles = soup.find_all("a", {"class", "jobtitle"})
TypeError: 'NoneType' object is not callable
表示soup.find_all是None。确保它不是 none。此外,我在您的代码中注意到的另一件可疑的事情是 imports
import BeautifulSoup
from BeautifulSoup import BeautifulSoup
确保导入其中任何一个并相应地修改
soup = BeautifulSoup(r.content)
您使用的 BeautifulSoup 3 似乎没有 find_all
,只有 findAll
.
如果您要使用 BeautifulSoup,请使用 findAll
3.
或使用BeautifulSoup 4 to use find_all
:
from bs4 import BeautifulSoup
下面对我有用 - jobtitle
是 h2
的 class 名称而不是 a
。我和 bs4 '4.4.0'
import requests
from bs4 import BeautifulSoup
url = "http://www.indeed.com/jobs? q=hardware+engineer&l=San+Francisco%2C+CA"
r = requests.get(url)
soup = BeautifulSoup(r.content)
job_titles = soup.find_all("h2", {"class", "jobtitle"})
for job in job_titles:
print job.text.strip()
打印-
Management Associate - Access & Channel Management
Airline Customer Service Agent (Korean Speaker preferred) SF...
Event Concierge
Flight Checker
Office Automation Clerk
Administrative Assistant III
Operations Admin I - CA
Cashier Receptionist, Grade 3, (Temporary)
Receptionist/Office Assistant
Full-Time Center Associate