【发布时间】:2016-10-11 16:50:05
【问题描述】:
输出显示:
“NoneType”对象没有“get_text”属性
我该如何解决这个问题?
response = requests.get("https://www.exar.com/careers")
soup = BeautifulSoup(response.text, "html.parser")
data = []
table_main = soup.find_all("table", class_="table")
#pprint(table_main)
for table_row in table_main:
job_category = table_row.find("th", class_="t3th").get_text().strip()
tds = table_row.find_all("td")
title = tds[0].find("td").get_text().strip()
location = tds[1].find("td").get_text().strip()
job = {
"job_location": location,
"job_title": title,
"job_dept": job_category
}
data.append(job)
pprint(data)
【问题讨论】:
-
你可以调试看看
table_row.find_all("td")是否返回了你期望的数据 -
好吧,看起来
tds[0].find("td")和/或tds[1].find("td")返回None。你可能想检查一下。 -
嗨@cricket_007,table_row.find_all("td") 的输出将找到我想要的所有数据,但是当我使用 tds = table_row.find_all("td") 和 title = tds [0].get_text().strip() 它只会显示 6 个数据。我该如何解决这个问题?
-
您希望展示什么?看一下html。
td元素是否超过六个? -
@cricket_007 它现在可以工作,但输出不是我想要的。一个部门有3个工作的部分。我该如何解决?
标签: python beautifulsoup