You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在存在'Easily apply'时用Selenium提取指定网页链接?

Got it, let's fix this so you only pull the links that have that orange 'Easily apply' badge. The key is to narrow your selection to only job entries that contain that specific phrase, instead of grabbing every link on the page. Here's how to do it step by step:

Step 1: Target the resultsCol section first

First, we'll restrict our search to the resultsCol block to avoid picking up links from other parts of the website. This ensures we're only looking at the job table you mentioned.

Step 2: Filter job entries with "Easily apply"

For each job entry in that table, we'll check if it includes the "Easily apply" text. If it does, we'll extract the corresponding job link.

Here's a Python code example that implements this:

from selenium import webdriver
from selenium.webdriver.common.by import By

# Assume your driver is already initialized and you've navigated to the page
driver = webdriver.Chrome()
driver.get("your-target-page-url")

# Get the resultsCol section to narrow our scope
results_col = driver.find_element(By.ID, "resultsCol")

# Find all job entries (adjust the selector if your table uses rows or divs)
# If jobs are in table rows:
job_entries = results_col.find_elements(By.TAG_NAME, "tr")

easily_apply_links = []

for entry in job_entries:
    try:
        # Check if the entry contains the "Easily apply" text
        entry.find_element(By.XPATH, ".//*[contains(text(), 'Easily apply')]")
        # If it does, extract the job link (adjust the selector to match your link's tag/class)
        job_link = entry.find_element(By.TAG_NAME, "a").get_attribute("href")
        easily_apply_links.append(job_link)
    except:
        # Skip entries without the "Easily apply" badge
        continue

# Print or process the filtered links
for link in easily_apply_links:
    print(link)

Alternative: Use a direct XPath selector

If you prefer a more concise approach, you can use an XPath query to directly select links that are within a job entry containing "Easily apply":

easily_apply_links = driver.find_elements(By.XPATH, "//div[@id='resultsCol']//table//a[../*[contains(text(), 'Easily apply')]]")

# Extract the href attributes
filtered_links = [link.get_attribute("href") for link in easily_apply_links]

Notes for adjustment:

  • If the "Easily apply" text is inside a specific element (like a span with a class such as easily-apply), replace the XPath text check with a class selector for better accuracy (e.g., ".//span[contains(@class, 'easily-apply')]").
  • Make sure the job link selector (like By.TAG_NAME, "a") matches the actual link element in your target page's HTML structure. You might need to use a class or ID instead if there are multiple links per job entry.

This way, you'll only get the links associated with jobs that have the orange "Easily apply" label, instead of all 250 links on the site.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:11:58