一. 简答题(共1题)
1. (简答题)
请爬取几个主流招聘网站中的一个,对电子信息专业能应聘的岗位进行爬取,找出需求求职岗位最多的10个岗位和5个工作地点
将代码和爬取的网站结果一起打包上交。
import requests
from bs4 import BeautifulSoup
from collections import Counter
import time
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
}
# 定义一个空列表来存储所有职位和工作地点
positions = []
work_places = []
def detail_url(url):
try:
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.text, 'lxml')
# 爬取工作职位
position = soup.select('.job-header .new_job_name span')[0].text
positions.append(position)
# 爬取该职位的工作地
work_place = soup.select('.job_position')[0].text
work_places.append(work_place)
except Exception as e:
print(f"爬取 {url} 时出错: {e}")
f
标签:计信,headers,Python,text,work,爬取,url,实训,import
From: https://blog.csdn.net/m0_57322261/article/details/145031565