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

网页抓取中绕过“Show More”按钮的技术实现问询

Bypassing "Show More" Buttons for Full Web Scraping

Hey there! This is such a common scenario when scraping lazy-loaded content—let’s walk through the most practical ways to skip that manual button click and grab all the data you need:

1. Sniff the Underlying API Requests (Most Reliable)

Most "Show More" buttons trigger AJAX/XHR requests to fetch additional content from the site’s backend, instead of loading a new page. Here’s how to find and use these:

  • Open your browser’s DevTools (F12 or Ctrl+Shift+I), go to the Network tab.
  • Click the "Show More" button on the page, and watch for new requests popping up (look for entries labeled XHR or Fetch).
  • Inspect the request URL and parameters—you’ll often see things like page=2, offset=60, or limit=60 that control how much content is returned.
  • Instead of scraping the HTML, you can directly send requests to this API endpoint, incrementing the page/offset parameter until you get an empty response or no more new content.
  • Pro tip: Don’t forget to copy important request headers (like User-Agent, Cookie, or Authorization) to avoid being blocked by the server.

2. Simulate the Button Click with Browser Automation

If you can’t track down the API, use tools like Selenium or Playwright to mimic human browsing behavior. This lets you automate clicking the button until all content loads:
Here’s a quick Python example with Selenium:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# Initialize the browser (use ChromeDriver or GeckoDriver)
driver = webdriver.Chrome()
driver.get("your_target_url_here")

while True:
    try:
        # Wait for the button to be clickable, then click it
        show_more_btn = WebDriverWait(driver, 10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "button.show-more-class"))
        )
        show_more_btn.click()
        # Add a small delay to let content load (adjust as needed)
        time.sleep(2)
    except:
        # Exit loop if the button is no longer found (all content loaded)
        break

# Now scrape the fully loaded page
full_content = driver.page_source
driver.quit()
  • Note: Some sites detect automation tools—try adding random delays, using headless mode with proper user-agent settings, or rotating proxies if you hit blocks.

3. Modify the Page’s DOM/JavaScript (Quick Hack)

Occasionally, sites load all content upfront but hide it with CSS or JavaScript. You can force it to display:

  • In DevTools’ Console tab, look for variables that control content visibility (e.g., maxItems = 60). Change that value to a large number (like 9999) and see if hidden content appears.
  • Or, use CSS selectors to remove hidden classes—for example, run document.querySelectorAll('.hidden-content').forEach(el => el.style.display = 'block') in the console.
  • This method is less reliable (site updates can break it) but works great for quick one-off scrapes.

4. Check for Hidden Content in the Page Source

Before diving into automation, do a quick check: view the page’s raw source (Ctrl+U) and search for content that should be loaded after clicking "Show More". If you find it, that means the site already sent all data to your browser—you just need to parse it directly, ignoring the button entirely.

Final Tips

  • Always respect the site’s robots.txt and scrape responsibly—don’t flood the server with too many requests at once.
  • If you hit rate limits, consider using a proxy service or adding longer delays between requests.

内容的提问来源于stack exchange,提问作者s.jones1212

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:08:09