from bs4 import BeautifulSoup
from pprint import pprint
import requests
url = "http://chk.tbe.taleo.net/chk01/ats/careers/searchResults.jsp?org=CDI&cws=1"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
table_main = soup.select("table#cws-search-results")
table = table_main.find_all("tr")
for tr in table:
job_title = tr.find_all("a")
job_location = tr.find_all("b")
job = {
"job_title": job_title,
"job_location": job_location
}
data.append(job)
pprint(jobs)
答案 0 :(得分:4)
您收到错误,因为Tag
返回Tag
个对象列表(本例中为1个项目列表)而不是单个find_all
对象,{{1 }}是Tag
对象的方法,而不是Python list
对象的方法。
变化:
table_main = soup.select("table#cws-search-results")
为:
table_main = soup.select_one("table#cws-search-results")
获取表示主表的Tag
对象,然后在该对象上调用find_all
将按预期工作。