我正在尝试使用 Python 制作 web Scraper,但在提取公司名称时出现问题。
def extract_indeed_job():
jobs = []
result = requests.get(f"{url}&start={0*LIMIT}")
result_soup = BeautifulSoup(result.text, "html.parser")
results = result_soup.find_all("a", {"class": "tapItem"})
for result in results:
title = result.find("h2", {"class": "jobTitle"}).find("span")["title"]
company = result.find("span", {"class": "companyName"}).get_text()
location = result.find("div", {"class": "companyLocation"}).get_text()
print(title, company, location)
有的帖子,h2 class="jobTitle"标签里面有两个span标签
我只需要获得跨度标题。所以我用这个标签写了。但是,Python 注意到关键错误并且它不起作用。
我能做些什么来解决?我的代码有问题吗??