Python,'NoneType'对象没有属性'get_text'

时间:2016-10-11 16:50:06

标签: python beautifulsoup

输出结果显示:

  

'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)

1 个答案:

答案 0 :(得分:2)

不确定您为什么要在td内找到td s:

title = tds[0].find("td").get_text().strip()
location = tds[1].find("td").get_text().strip()

将其替换为:

title = tds[0].get_text().strip()
location = tds[1].get_text().strip()

适合我。

相关问题