Skip to content

Instantly share code, notes, and snippets.

import { PlaywrightCrawler, Dataset } from 'crawlee';
const maxRepoCount = 100;
const crawler = new PlaywrightCrawler({
requestHandler: async ({ page, infiniteScroll }) => {
// Click the Load more button and scroll until
// `maxRepoCount` repositories are found.
console.log('Clicking and scrolling.');
await infiniteScroll({
import { PlaywrightCrawler } from 'crawlee';
const maxRepoCount = 100;
const crawler = new PlaywrightCrawler({
requestHandler: async ({ page, infiniteScroll }) => {
// Click the Load more button and scroll until
// `maxRepoCount` repositories are found.
console.log('Clicking and scrolling.');
await infiniteScroll({
import { PlaywrightCrawler } from 'crawlee';
const crawler = new PlaywrightCrawler({
requestHandler: async ({ page }) => {
// Extract data from the page. Selecting all 'article' elements
// will return all the repository cards we're looking for.
const repos = await page.$$eval('article.border', (repoCards) => {
return repoCards.map(card => {
const [user, repo] = card.querySelectorAll('h3 a');
const stars = card.querySelector('#repo-stars-counter-star').getAttribute('title');
import { PlaywrightCrawler } from 'crawlee';
const crawler = new PlaywrightCrawler({
requestHandler: async ({ page }) => {
console.log(await page.title());
}
})
await crawler.run(['https://github.com/topics/javascript']);
const Apify = require('apify');
Apify.main(async () => {
// Get the HTML of a web page
const { body } = await Apify.utils.requestAsBrowser({ url: 'https://www.example.com' });
console.log(body);
});
@mnmkng
mnmkng / playwright-example-3.js
Last active November 14, 2022 12:58
Code example: How to scrape the web with Playwright 3
// Import the playwright library into our scraper.
const playwright = require('playwright');
async function main() {
// Open a Chromium browser. We use headless: false
// to be able to watch what's going on.
const browser = await playwright.chromium.launch({
headless: false,
});
// Open a new page / tab in the browser.
@mnmkng
mnmkng / playwright-example-2.js
Last active November 14, 2022 12:56
Code example: How to scrape the web with Playwright 2
// Import the playwright library into our scraper.
const playwright = require('playwright');
async function main() {
// Open a Chromium browser. We use headless: false
// to be able to watch what's going on.
const browser = await playwright.chromium.launch({
headless: false
});
// Open a new page / tab in the browser.
@mnmkng
mnmkng / playwright.js
Last active September 20, 2021 12:16
Code example: How to scrape the web with Playwright
// Import the playwright library into our scraper.
const playwright = require('playwright');
async function main() {
// Open a Chromium browser. We use headless: false
// to be able to watch what's going on.
const browser = await playwright.chromium.launch({
headless: false
});
// Open a new page / tab in the browser.
const Apify = require('apify');
Apify.main(async () => {
// Get queue and enqueue first url.
const requestQueue = await Apify.openRequestQueue();
const enqueueUrl = async url => requestQueue.addRequest(new Apify.Request({ url }));
await enqueueUrl('https://news.ycombinator.com/');
const crawlerConfig = {
launchPuppeteerOptions: {
@mnmkng
mnmkng / bonusova_uloha.rb
Last active March 6, 2017 23:21
#PES S02 S03
pole = ["123", "4a5", "Ka", "5,5,1", "0,1", "15,5", "1x", "15.5", "1,"]
suma = 0
pole.each do |item|
if item =~ /^\d+(,?\d+)$/
nums = item.gsub(",", "")
nums.length.times do |i|
suma += nums[i].to_i
end