首页 文章

Python错误:TypeError:'NoneType' object不可调用

提问于
浏览
2

下面是我的代码和我得到的错误

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

3 回答

  • 0

    以下是我的工作 - jobtitleh2 的类名 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()
    

    Prints-

    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
    
  • 2

    看起来你正在使用的BeautifulSoup 3没有 find_all ,只有 findAll .

    如果您将使用BeautifulSoup 3,请使用findAll .

    或使用BeautifulSoup 4使用find_all

    from bs4 import BeautifulSoup
    
  • 1

    它表明soup.find_all是None . 确保它不是没有 . 而且,我在你的代码中注意到的另一个可疑的东西是导入

    import BeautifulSoup
    from BeautifulSoup import BeautifulSoup
    

    确保导入其中任何一个并进行相应的修改

    soup = BeautifulSoup(r.content)
    

相关问题