python爬取牛客网站招聘信息100条,包括公司名称、岗位要求、工作类型、工作名称、薪资、城市名称、公司规模、岗位职责、每周工作天数等信息,并写入文本
时间: 2023-07-04 16:29:42 浏览: 118
好的,这个问题我可以回答。首先,我们需要使用 Python 中的 requests 库来请求牛客网站的招聘信息页面,并使用 BeautifulSoup 库从 HTML 中解析出需要的信息。最后,我们可以使用 Python 中的文件操作函数将信息写入文本文件中。
以下是示例代码:
```python
import requests
from bs4 import BeautifulSoup
# 请求牛客网站的招聘信息页面
url = 'https://www.nowcoder.com/job/center?type=1&page=1'
response = requests.get(url)
# 解析 HTML 获取招聘信息
soup = BeautifulSoup(response.text, 'html.parser')
jobs = soup.find_all('div', class_='job-item')
# 将招聘信息写入文本文件
with open('jobs.txt', 'w', encoding='utf-8') as f:
for job in jobs:
company = job.find('div', class_='job-name').find('a').text
requirements = job.find('div', class_='job-desc').find('p').text.strip()
work_type = job.find('div', class_='job-tags').find_all('span')[0].text
job_name = job.find('div', class_='job-tags').find_all('span')[1].text
salary = job.find('div', class_='salary').text.strip()
city = job.find('div', class_='city').text.strip()
company_size = job.find('div', class_='scale').text.strip()
job_duty = job.find('div', class_='job-duty').find('p').text.strip()
work_days = job.find('div', class_='job-duty').find_all('p')[1].text.strip()
f.write(f'公司名称:{company}\n')
f.write(f'岗位要求:{requirements}\n')
f.write(f'工作类型:{work_type}\n')
f.write(f'工作名称:{job_name}\n')
f.write(f'薪资:{salary}\n')
f.write(f'城市名称:{city}\n')
f.write(f'公司规模:{company_size}\n')
f.write(f'岗位职责:{job_duty}\n')
f.write(f'每周工作天数:{work_days}\n\n')
```
这段代码将会爬取第一页的招聘信息,并将每个招聘信息的公司名称、岗位要求、工作类型、工作名称、薪资、城市名称、公司规模、岗位职责、每周工作天数等信息写入到一个名为 `jobs.txt` 的文本文件中。如果需要爬取更多的招聘信息,可以改变请求的页面 URL,并修改代码中的写入文件方式。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)