Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/examples/ulixee.org.ts
1028 views
1
import { Handler, Agent } from 'secret-agent';
2
3
(async () => {
4
const handler = new Handler({ maxConcurrency: 2 });
5
6
async function getDatasetCost(agent: Agent) {
7
const dataset = agent.input;
8
let href = dataset.href;
9
if (!href.startsWith('http')) href = `https://ulixee.org${href}`;
10
console.log(href);
11
await agent.goto(href);
12
await agent.waitForPaintingStable();
13
console.log('Page Loaded', href);
14
const cost = await agent.document.querySelector('.cost .large-text').textContent;
15
console.log('Cost of %s is %s', dataset.name, cost);
16
agent.output.cost = cost;
17
}
18
19
handler.dispatchAgent(async agent => {
20
await agent.goto('https://ulixee.org');
21
const datasetLinks = await agent.document.querySelectorAll('a.DatasetSummary');
22
for (const link of datasetLinks) {
23
const name = await link.querySelector('.title').textContent;
24
const href = await link.getAttribute('href');
25
const input = { name, href };
26
const agentOptions = { name, input };
27
handler.dispatchAgent(getDatasetCost, agentOptions);
28
}
29
});
30
31
await handler.waitForAllDispatches();
32
await handler.close();
33
})();
34
35