我正在使用 BS 来解析职位列表网站。它工作正常,但只返回 div 的第一项。我希望它使用名为 {'class': 'job-item'} 的类迭代每个 div。我已经通读了文档并尝试了一些尝试以使其正常工作,但我只是被卡住了。
from bs4 import BeautifulSoup
import urllib2
import time
quote_page = 'https://jobbio.com/search/jobs?query=Developer&location=dublin§or='
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, 'html.parser')
divs = soup.findAll({'class': 'job-item'})
for div in divs:
role_box = soup.find(attrs={'class': 'color-dark-grey'})
role = role_box.text.strip() # strip() is used to remove starting and trailing
company_box = soup.find(attrs={'class': 'color-greenish-blue'})
company = company_box.text.strip() # strip() is used to remove starting and trailing
location_box = soup.find(attrs={'class': 'color-grey'})
location = location_box.text.strip() # strip() is used to remove …Run Code Online (Sandbox Code Playgroud)