帮我写一段爬取boss直聘的代码
时间: 2023-07-10 21:08:01 浏览: 142
好的,这里给您提供一个 Python 的爬取 Boss 直聘的例子,需要使用 requests 库和 BeautifulSoup 库:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.zhipin.com/c101280100/?query=Python&page=1&ka=page-1'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
jobs = soup.find_all('div', {'class': 'job-list'})
for job in jobs:
job_name = job.find('div', {'class': 'job-title'}).text.strip()
company_name = job.find('div', {'class': 'company-text'}).find('a').text.strip()
salary_info = job.find('span', {'class': 'red'}).text.strip()
job_info = job.find('div', {'class': 'info-primary'}).find_all('p')
job_addr = job_info[0].text.strip()
job_exp = job_info[1].text.strip()
job_edu = job_info[2].text.strip()
print(job_name, company_name, salary_info, job_addr, job_exp, job_edu)
```
这段代码可以爬取 Boss 直聘上关于 Python 职位的第一页数据。您可以根据需要修改 url 中的参数来获取更多页面的数据。
阅读全文
相关推荐
















