python爬虫智联招聘数据
时间: 2024-01-21 14:14:10 浏览: 89
以下是使用Python爬虫获取智联招聘数据的步骤:
1. 导入所需的库和模块:
```python
import requests
from bs4 import BeautifulSoup
import pandas as pd
```
2. 发送请求并获取网页内容:
```python
url = 'https://www.zhaopin.com/'
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)
```
3. 解析网页内容:
```python
soup = BeautifulSoup(response.text, 'html.parser')
```
4. 提取所需的数据:
```python
job_list = soup.find_all('div', class_='joblist-box__iteminfo')
data = []
for job in job_list:
title = job.find('a', class_='joblist-box__jobname').text.strip()
company = job.find('a', class_='joblist-box__companyname').text.strip()
salary = job.find('span', class_='joblist-box__jobmoney').text.strip()
data.append([title, company, salary])
```
5. 将数据保存到DataFrame中:
```python
df = pd.DataFrame(data, columns=['职位', '公司', '薪资'])
```
6. 将数据保存到Excel文件中:
```python
df.to_excel('zhaopin_data.xlsx', index=False)
```
以上是使用Python爬虫获取智联招聘数据的基本步骤。你可以根据自己的需求进行进一步的数据处理和分析。
阅读全文