我一直收到找不到节点的错误。我转而尝试使用 jQuery。没运气。我现在就在这。page.text 不起作用。我得到了节点错误。我正在尝试通过提供案例编号来抓取https://web6.seattle.gov/courts/ECFPortal/Default.aspx以获取案例信息和文件。
const Apify = require('apify');
const {
puppeteer
} = Apify.utils;
const saveScreen = async(page, key = 'debug-screen') = > {
const screenshotBuffer = await page.screenshot({
fullPage: true
});
await Apify.setValue(key, screenshotBuffer, {
contentType: 'image/png'
});
};
Apify.main(async() = > {
// Launch Puppeteer
const browser = await Apify.launchPuppeteer();
const page = await browser.newPage();
await page.goto('https://web6.seattle.gov/courts/ECFPortal/Default.aspx');
await page.addScriptTag({
url: 'https://code.jquery.com/jquery-3.2.1.min.js'
});
await page.waitForFunction(() = > window.jQuery);
page.evaluate(() = > $('span:contains("Case Information")').click());
//await page.waitForNavigation();
await page.waitFor(4000);
const input = await Apify.getInput()
console.log('json stringify input: ' + JSON.stringify(input))
const caseNumber = input['court_case'];
console.log('CASE NUMBER: ' + caseNumber)
var html = await page.$eval('body', e = > e.outerHTML);
const output2 = {
html,
crawledAt: new Date(),
};
await Apify.setValue('HTMltestOUTPUT', output2);
console.log('html to test.');
page.evaluate(() = > $('#ContentPlaceHolder1_CaseDocuments1_CaseSearch1_txtCaseNumber').val("585344"));
await saveScreen(page, 'test-screen');
await page.waitFor(1000);
console.log('Attempted to enter case number');
page.evaluate(() = > $('#ContentPlaceHolder1_CaseDocuments1_CaseSearch1_btnSearch').click());
console.log('Attempted to click button');
// Times-out here
//await page.waitForNavigation();
console.log('Attempted to wait for navigation');
// Get cookies
const cookies = await page.cookies();
console.log('Attempted to wait for cookies');
var html = await page.$eval('body', e = > e.outerHTML);
// And then save output
const output = {
html,
crawledAt: new Date(),
};
console.log('My output:');
console.dir(output);
await Apify.setValue('OUTPUT', output);
await browser.close();
console.log('Done.');
});