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

基于下拉框的查询网站底层数据提取:剑桥国际学校表格爬取咨询

Hey there! Let's walk through how to extract all rows from that Cambridge International school table. Since the table only loads once you pick a country and city, I’ve got a few approaches tailored to different skill levels—pick the one that fits you best:

1. Manual Export (No Coding Needed)

This is the simplest route if you just need data for one or two locations:

  • First, select your target country and city on the page, wait for the table to fully load.
  • Select the entire table: You can click the top-left corner of the table, use Ctrl+A (Windows) / Cmd+A (Mac) and adjust the selection to only include the table, or right-click the table → Inspect, find the <table> tag in the Elements panel, right-click it → Copy → Copy element.
  • Paste into Excel or Google Sheets: The table structure will auto-preserve when you paste directly. If you copied the HTML element, you can also paste it into a text editor and convert it to a table format if needed.
  • Bonus trick: Use a browser extension built for table export (look for tools that let you save tables as CSV/Excel directly with a right-click).
2. Using Browser Developer Tools (Basic Tech Skills)

Great if you want a quick, code-light way to export clean CSV data:

  • After selecting your country/city and loading the table, press F12 to open your browser’s Developer Tools.
  • Switch to the Console tab.
  • Paste this JavaScript code and hit Enter:
// Locate the table element
const table = document.querySelector('table');
if (!table) {
  console.log('No table found! Double-check you selected a country/city first.');
} else {
  // Extract table headers
  const headers = Array.from(table.querySelectorAll('th')).map(th => th.textContent.trim());
  // Extract each row's data
  const rows = Array.from(table.querySelectorAll('tbody tr')).map(tr => {
    return Array.from(tr.querySelectorAll('td')).map(td => td.textContent.trim());
  });
  // Format as CSV and download
  const csvContent = [headers.join(','), ...rows.map(row => row.join(','))].join('\n');
  const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', 'cambridge_schools.csv');
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}
  • Your browser will automatically download a CSV file containing every row from the table.
3. Python Web Scraping (For Advanced Users)

Perfect if you need to batch-extract data for multiple countries/cities:

  • First, install the required libraries:
pip install selenium webdriver-manager pandas
  • Use this sample code (adjust element selectors to match the page’s actual HTML—use Developer Tools to check IDs/classes):
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd

# Initialize Chrome browser
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get('http://www.cambridgeinternational.org/i-want-to/find-a-cambridge-school/')

# Select your target country (replace with your desired country name)
country_dropdown = Select(driver.find_element(By.ID, 'country'))
country_dropdown.select_by_visible_text('United States')

# Select your target city (replace with your desired city name)
city_dropdown = Select(driver.find_element(By.ID, 'city'))
city_dropdown.select_by_visible_text('New York')

# Trigger the search (adjust the selector to match the page's search button)
search_button = driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]')
search_button.click()

# Wait for the table to load
driver.implicitly_wait(10)

# Extract table data into a DataFrame
table_element = driver.find_element(By.TAG_NAME, 'table')
school_data = pd.read_html(table_element.get_attribute('outerHTML'))[0]

# Save to CSV
school_data.to_csv('cambridge_schools.csv', index=False)

# Clean up: close the browser
driver.quit()
  • Note: You’ll need to tweak the element selectors (like the dropdown IDs or search button CSS) if the page’s HTML structure changes. Use the Elements tab in Developer Tools to find the correct attributes.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:51:41