You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
729 B
12 lines
729 B
const { chromium } = require('playwright');
|
|
(async () => {
|
|
const browser = await chromium.launch({ headless: true, args: ['--no-sandbox'] });
|
|
const page = await browser.newPage();
|
|
await page.goto('https://weather.baidu.com/weather/北京', { waitUntil: 'domcontentloaded', timeout: 15000 });
|
|
await page.waitForSelector('.weather-now-info', { timeout: 10000 });
|
|
const temp = await page.$eval('.weather-now-temp', el => el.innerText.trim());
|
|
const desc = await page.$eval('.weather-now-desc', el => el.innerText.trim());
|
|
const wind = await page.$eval('.weather-now-wind', el => el.innerText.trim());
|
|
console.log(`✅ 2026年3月10日北京天气:${desc},温度${temp},${wind}`);
|
|
await browser.close();
|
|
})();
|