Boss直聘数据采集及分析
我主要采集了Boss web端西安5月Python招聘情况,后面会在代码注释中进行解释
采集
问题点
为了绕过boss直聘网站对selenium的检测需要做以下初始化工作:
- 首先开启:chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile";这句话在你的谷歌浏览器可执行文件夹运行,会在你的C:\selenum\ 生成一大堆文件
- 其次代码中需要添加:chrome_options.add_experimental_option('debuggerAddress','127.0.0.1:9222');开启谷歌浏览器代理,为了绕过boss对selenium的检测
- chrome_driver = r"D:\chrome-selenium\chromedriver_win32\chromedriver.exe" # selenium驱动
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options) # 将代理添加进来
注意谷歌浏览器版本要与你的chromedriver版本一致,否则无法启动。chromeDrive下载网址
#!/usr/bin/python3
# encoding: utf-8
"""
@version: v1.0
@author: W_H_J
@license: Apache Licence
@contact: 415900617@qq.com
@software: PyCharm
@file: Boss.py
@time: 2020/5/8 15:21
@describe: boss直聘数据抓取
chromdriver :https://npm.taobao.org/mirrors/chromedriver
selenium: D:\chrome-selenium\chromedriver_win32\chromedriver.exe
参考:https://blog.youkuaiyun.com/qq_35531549/article/details/89023525
首先开启:chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile"
上面这句话在你的谷歌浏览器可执行文件夹运行,会在你的C:\selenum\ 生成一大堆文件
其次添加:chrome_options.add_experimental_option('debuggerAddress','127.0.0.1:9222')
上面这句话,相当于开启你的谷歌浏览器代理,为了绕过boss对selenium的检测
"""
import hashlib
import sys
import os
import time
import requests
from pyquery import PyQuery as pq
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
from config.MysqlContent import DBHelper
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
sys.path.append("..")
UA = UserAgent() # 获取fake_useragent中的浏览器请求头
DB = DBHelper() # 我自己写的MySQL助手,如果不存入MySQL,可以忽略
def driver_chrome():
"""
加载selenium浏览器
:return:
"""
try:
agent = UA.random
chrome_options = Options()
chrome_options.add_experimental_option('debuggerAddress', '127.0.0.1:9222') # 开启代理模式
chrome_driver = r"D:\chrome-selenium\chromedriver_win32\chromedriver.exe" # 加载自己本地驱动
driver