【发布时间】:2020-05-14 13:14:05
【问题描述】:
我对本网站上发布的其他问题没有任何运气。 我对这个程序的目标是从 Indeed.com 上抓取招聘信息。我遇到了属性错误。我不知道为什么会收到此错误,因为我要确保 HTML 和 Python 之间的标签匹配。谁能帮我解决这个问题?
代码:
import urllib.request as urllib
from bs4 import BeautifulSoup
import csv
# empty array for results
results = []
# initialize the Indeed URL to url string
url = 'https://www.indeed.com/jobs?q=software+developer&l=Phoenix,+AZ&jt=fulltime&explvl=entry_level'
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
results = soup.find_all('div', attrs={'class': 'jobsearch-SerpJobCard'})
for i in results:
title = i.find('div', attrs={"class":"title"})
print('\ntitle:', title.text.strip())
salary = i.find('span', attrs={"class":"salaryText"})
print('salary:', salary.text.strip())
company = i.find('span', attrs={"class":"company"})
print('company:', company.text.strip())
错误日志:
Traceback(最近一次调用最后一次):文件“c:/Users/Scott/Desktop/code/ScrapingIndeed/index.py”,第 16 行,在 print('salary:',salary.text.strip())
Scott@DESKTOP-MS37V5T MINGW64 ~/Desktop/code
$ AttributeError: 'NoneType' 对象没有属性 'text'
我正在尝试抓取来自 Indeed.com 的代码:
<span class="salaryText">
$15 - $30 an hour</span>
【问题讨论】:
-
你好 Scott,请提供最小的工作示例,我们这里不使用截图。
-
请提供完整的错误日志,加上在一些 scpp 字段中,你没有得到完整的数据,即你是空的,你需要处理它
标签: python web-scraping attributeerror