python 爬取岗位
Python是一门功能强大的编程语言,可以用它来爬取网页上的各种数据,比如我们可以用Python来爬取岗位信息,这对求职者来讲是非常有用的。
import requests from bs4 import BeautifulSoup def get_jobs(url): res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') jobs = soup.find_all('div', {'class': 'job'}) for job in jobs: title = job.find('h3', {'class': 'title'}).text company = job.find('p', {'class': 'company'}).text.strip() location = job.find('p', {'class': 'location'}).text salary = job.find('p', {'class': 'salary'}).text print(f'Title: {title}\nCompany: {company}\nLocation: {location}\nSalary: {salary}\n') if __name__ == '__main__': url = 'https://www.xxx.com/jobs' get_jobs(url)
在上面的代码中,我们使用了requests和BeautifulSoup这两个库,requests可以用来发送http要求,而BeautifulSoup可以用来解析html页面。
我们通过传入url参数来获得网页信息,然后使用find_all方法来找到所有的岗位信息,接着我们使用find方法来找到每一个岗位信息的标题、公司、地点和薪资。最后我们通过print方法来输出这些信息。
通过这篇文章,我们可以看到怎样使用Python来爬取岗位信息,这对求职者来讲是非常实用的。
文章来源:丸子建站
文章标题:python 爬取岗位
https://www.wanzijz.com/view/74956.html