You need to enable JavaScript to run this app. 如何用Python爬取JS渲染滚动加载的Autodesk Workday招聘数据?
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python爬取JS渲染滚动加载的Autodesk Workday招聘数据?

Autodesk Workday招聘页面爬取实现方案

现有代码的基础优化

现有基础代码可做两点适配优化,保证后续爬取稳定运行:

  • 补充Chrome反爬配置,避免被网站的自动化检测机制拦截
  • 替换硬编码的chromedriver路径写法,适配Selenium 4+的自动驱动管理能力(如果使用旧版本Selenium,可保留原有路径写法,不影响后续逻辑)
    调整后的基础初始化代码:
from bs4 import BeautifulSoup
import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from datetime import datetime
import time
import json

startTime = datetime.now()
print('startTime', startTime)

# 配置Chrome选项
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])

# 初始化驱动(旧版本可替换为原有的webdriver.Chrome(executable_path=你的本地路径))
driver = webdriver.Chrome(options=chrome_options)
wait = WebDriverWait(driver, 10)

# 访问目标页面
target_url = "https://autodesk.wd1.myworkdayjobs.com/Ext/0/refreshFacet/318c8bb6f553100021d223d9780d30be"
driver.get(target_url)

无限滚动加载全量职位

目标页面采用滚动触底自动加载的机制,需要通过循环滚动的方式触发所有职位加载,直到页面高度不再变化、无新内容加载为止:

last_height = driver.execute_script("return document.body.scrollHeight")
while True:
    # 滚动到页面底部
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    # 等待新内容加载
    time.sleep(2)
    # 计算滚动后的页面高度
    new_height = driver.execute_script("return document.body.scrollHeight")
    # 判断是否加载完全(高度不再变化说明没有新内容)
    if new_height == last_height:
        break
    last_height = new_height

目标字段提取逻辑

需要明确:职位描述、最低任职要求、全职/兼职属性这类深度字段不会直接渲染在列表页,需要先从列表页获取所有职位的详情链接,再逐个访问详情页完成提取。
所有元素定位优先使用页面固定的data-automation-id属性,避免随机生成的CSS类名变更导致代码失效,具体提取流程:

  1. 先从列表页批量提取所有职位的基础信息(职位链接、列表页可见的地点)
  2. 逐个遍历详情链接,等待页面加载完成后提取深度字段
    实现代码:
# 第一步:从列表页获取所有职位卡片
job_cards = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "li[data-automation-id='jobTitle']")))
job_list = []

# 遍历卡片提取列表页可直接获取的字段
for card in job_cards:
    job_link_elem = card.find_element(By.CSS_SELECTOR, "a")
    job_url = job_link_elem.get_attribute("href")
    job_location = card.find_element(By.CSS_SELECTOR, "[data-automation-id='locations']").text
    job_list.append({
        "job_url": job_url,
        "job_location": job_location
    })

# 第二步:逐个访问详情页提取深度字段
for job in job_list:
    driver.get(job["job_url"])
    # 等待详情页加载
    wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "[data-automation-id='jobPostDescription']")))
    # 提取职位描述
    job_desc = driver.find_element(By.CSS_SELECTOR, "[data-automation-id='jobPostDescription']").text
    # 提取雇佣类型(全职/兼职)
    emp_type = driver.find_element(By.CSS_SELECTOR, "[data-automation-id='timeType']").text
    # 提取最低任职要求
    req_blocks = driver.find_elements(By.CSS_SELECTOR, "[data-automation-id='qualifications']")
    min_req = ""
    for block in req_blocks:
        if "Minimum Qualifications" in block.text:
            min_req = block.text
            break
    # 补充字段到结果集
    job["job_description"] = job_desc
    job["employment_type"] = emp_type
    job["min_requirement"] = min_req
    # 控制访问频率,避免被拦截
    time.sleep(1.5)

JSON结果导出

将提取完成的数据集直接转为格式化JSON文件存储:

# 导出为JSON文件
with open("autodesk_jobs.json", "w", encoding="utf-8") as f:
    json.dump(job_list, f, ensure_ascii=False, indent=2)

# 关闭驱动
driver.quit()
endTime = datetime.now()
print(f"爬取完成,总耗时:{endTime - startTime}")

常见问题规避

  • 操作页面元素时尽量用显式等待替代固定sleep,避免因为页面加载慢导致元素定位失败(StaleElementReferenceException)
  • 控制详情页的访问间隔,避免短时间高频请求被网站临时封禁IP
  • 提取文本时自动去除多余换行和空格,保证存储的JSON内容整洁

内容的提问来源于stack exchange,提问作者netxperia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.20 17:45:01