Python中,“非类型”对象没有属性“get_text”

Python中,“非类型”对象没有属性“get_text”,python,beautifulsoup,Python,Beautifulsoup,结果显示: “非类型”对象没有属性“获取文本” 我怎样才能解决这个问题 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 tabl

结果显示:

“非类型”对象没有属性“获取文本”

我怎样才能解决这个问题

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)

不确定您为什么要在此处的tds中查找tds:

将其替换为:

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

对我来说很有用。

您可以进行调试,看看table\u row.find\u alltd是否返回了所需的数据。看起来像tds[0]。findtd和/或tds[1]。findtd不返回任何数据。您可能想检查一下。Hi@cricket\u 007,table\u row.find\u alltd此操作的输出将找到我需要的所有数据,但当我使用tds=table\u row.find\u alltd和title=tds[0]时,get\u text.strip仅显示6个数据。我怎样才能解决这个问题?你想展示什么?看看html。有六个以上的td元素吗?@cricket_007现在可以工作了,但输出不是我想要的。一个部门中有3个职位的部分。我怎样才能解决这个问题?谢谢。这是可行的,但我现在的问题是它只会显示1个类别;1份工作。有些类别有一个以上的工作。我该怎么办?
title = tds[0].get_text().strip()
location = tds[1].get_text().strip()