python爬取拉勾网招聘
时间: 2023-12-29 11:05:03 浏览: 100
以下是使用Python爬取拉勾网招聘信息的示例代码:
```python
import requests
from bs4 import BeautifulSoup
# 设置请求头,模拟浏览器访问
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'
}
# 发送请求,获取搜索结果页的HTML内容
url = 'https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput='
response = requests.get(url, headers=headers)
html = response.text
# 使用BeautifulSoup解析HTML内容
soup = BeautifulSoup(html, 'html.parser')
# 找到招聘职位信息所在的标签
job_list = soup.find_all('li', class_='con_list_item')
# 遍历每个职位信息标签,提取所需信息
for job in job_list:
# 提取职位名
job_name = job.find('h3').text.strip()
# 提取薪资
salary = job.find('span', class_='money').text.strip()
# 提取公司名
company = job.find('div', class_='company_name').text.strip()
# 打印提取的信息
print("职位名:", job_name)
print("薪资:", salary)
print("公司名:", company)
print("--")
```
阅读全文