Python爬虫,使用BeautifulSoup可以轻松解析页面结果,下面是使用该方法爬取boss页面的职位信息:包括职位名称、薪资、地点、公司名称、公司融资情况等信息。通过这个示例可以轻松看到BeautifulSoup的使用方法。
import requests
from bs4 import BeautifulSoup
from middlewares import get_random_proxy,get_random_agent
import time
class Boss_Spider(object):
def __init__(self, page=3):
self.proxies = []
self.verify_pro = []
self.page = page
self.headers = {}
#第一步:获取首页所有招聘连接
def Parse_pre(self):
base_url = 'https://www.zhipin.com/'
headers = get_random_agent()
proxy = get_random_proxy()
time.sleep(1)
resp = requests.get(base_url, headers=headers)
if resp.status_code == 200:
soup = BeautifulSoup(resp.text, 'lxml')
for job_menu in soup.find_all(class_='menu-sub'):