Chrono24
Try for free
No credit card required
View all Actors![Chrono24](https://apify.com/img/store/actor_picture.svg)
Chrono24
predictable_leaf/chrono24
Try for free
No credit card required
This is a beta version, This actor is use to fetch the data of chrono24 watches select any particular category paste the url in input
.actor/Dockerfile
1# Specify the base Docker image. You can read more about
2# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
3# You can also use any other image from Docker Hub.
4FROM apify/actor-node:18
5
6# Copy just package.json and package-lock.json
7# to speed up the build using Docker layer cache.
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --omit=dev --omit=optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --omit=dev --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version \
21 && rm -r ~/.npm
22
23# Next, copy the remaining files and directories with the source code.
24# Since we do this after NPM install, quick build will be really fast
25# for most source file changes.
26COPY . ./
27
28
29# Run the image.
30CMD npm start --silent
.actor/actor.json
1{
2 "actorSpecification": 1,
3 "name": "my-actor",
4 "title": "Scrape single page in JavaScript",
5 "description": "Scrape data from single page with provided URL.",
6 "version": "0.0",
7 "meta": {
8 "templateId": "js-start"
9 },
10 "input": "./input_schema.json",
11 "dockerfile": "./Dockerfile"
12}
.actor/input_schema.json
1{
2 "title": "Scrape data from a web page",
3 "type": "object",
4 "schemaVersion": 1,
5 "properties": {
6 "url": {
7 "title": "URL of the page",
8 "type": "string",
9 "description": "The URL of website you want to get the data from.",
10 "editor": "textfield",
11 "prefill": "https://www.chrono24.in/rolex/index.htm"
12 }
13 },
14 "required": ["url"]
15}
src/main.js
1// Axios - Promise based HTTP client for the browser and node.js (Read more at https://axios-http.com/docs/intro).
2import axios from 'axios';
3// Cheerio - The fast, flexible & elegant library for parsing and manipulating HTML and XML (Read more at https://cheerio.js.org/).
4import * as cheerio from 'cheerio';
5// Apify SDK - toolkit for building Apify Actors (Read more at https://docs.apify.com/sdk/js/).
6import { Actor } from 'apify';
7// this is ESM project, and as such, it requires you to specify extensions in your relative imports
8// read more about this here: https://nodejs.org/docs/latest-v18.x/api/esm.html#mandatory-file-extensions
9// import { router } from './routes.js';
10
11// The init() call configures the Actor for its environment. It's recommended to start every Actor with an init().
12await Actor.init();
13
14// Structure of input is defined in input_schema.json
15const input = await Actor.getInput();
16const { url } = input;
17
18// Fetch the HTML content of the page.
19const response = await axios.get(url);
20
21// Parse the downloaded HTML with Cheerio to enable data extraction.
22const $ = cheerio.load(response.data);
23
24 const okButton = $("button:contains('OK')");
25 if (okButton.length > 0) {
26 // Click the OK button if found
27 console.log('Clicking OK button');
28 // Perform the action you need (e.g., submit a form, close the modal)
29 // For simplicity, here, we're just logging that the OK button would be clicked.
30 }
31
32
33// Extract all headings from the page (tag name and text).
34const heading = [];
35
36 const items = $(".article-item-container.wt-search-result.article-image-carousel");
37 items.each((index, element) => {
38 const obj = {};
39 const id = $(element).find('a').attr('data-article-id');
40 const link = $(element).find('a').attr('href');
41 const titleElement = $(element).find('.text-sm.text-sm-md.text-bold.text-ellipsis').text().trim();
42 const description = $(element).find('.text-sm.text-sm-md.text-ellipsis.m-b-2').text().trim();
43 // Adjusted regex to extract the numeric part of the price
44 const priceText = $(element).find('.d-flex.justify-content-between.align-items-end.m-b-1 .text-bold').text().trim();
45 const priceMatch = priceText.match(/(\d+(?:,\d{3})*)/);
46 const price = priceMatch ? parseInt(priceMatch[1].replace(/,/g, '')) : null;
47
48 const location = $(element).find('.d-flex.justify-content-between.align-items-end.m-b-1 .text-sm.text-uppercase').text().trim();
49 const currency = $(element).find('.d-flex.justify-content-between.align-items-end.m-b-1 .currency').text().trim();
50
51 obj.id = id;
52 obj.link = "https://www.chrono24.in/"+link;
53 obj.titleElement = titleElement;
54 obj.description = description;
55 obj.price = price;
56 obj.location = location;
57 obj.currency = currency;
58 heading.push(obj);
59 });
60
61 // Loop to extract additional data (ratings)
62 for (let i = 0; i < heading.length; i++) {
63 const EachProduct = {};
64 try {
65 const responseItem = await axios.get(heading[i].link);
66 const $item = cheerio.load(responseItem.data);
67
68 const okButtonItem = $item('button:contains("OK")');
69 if (okButtonItem.length > 0) {
70 console.log('OK button found for the second request. Clicking...');
71 }
72
73 const rating = $item('.m-b-2.d-flex.justify-content-between span.rating').text().trim();
74 const maximumImageSize = [];
75 const listOfImages = $item('div[data-zoom-image]');
76
77 listOfImages.each((index, element) => {
78 const imageSmall = $item(element).attr('data-zoom-image');
79 maximumImageSize.push(imageSmall);
80 });
81 EachProduct.rating = rating;
82 EachProduct.images = maximumImageSize;
83 } catch (error) {
84 console.error('Error:', error.message);
85 EachProduct.rating = 'null';
86 EachProduct.imageSmall = "not found";
87 }
88 heading[i].EachProduct = EachProduct;
89 }
90
91// Save headings to Dataset - a table-like storage.
92await Actor.pushData(heading);
93
94// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit().
95await Actor.exit();
.dockerignore
1# configurations
2.idea
3
4# crawlee and apify storage folders
5apify_storage
6crawlee_storage
7storage
8
9# installed files
10node_modules
11
12# git folder
13.git
.gitignore
1# This file tells Git which files shouldn't be added to source control
2.DS_Store
3.idea
4dist
5node_modules
6apify_storage
7storage/*
8!storage/key_value_stores
9storage/key_value_stores/*
10!storage/key_value_stores/default
11storage/key_value_stores/default/*
12!storage/key_value_stores/default/INPUT.json
package.json
1{
2 "name": "js-scrape-single-page",
3 "version": "0.0.1",
4 "type": "module",
5 "description": "This is an example of an Apify actor.",
6 "engines": {
7 "node": ">=18.0.0"
8 },
9 "dependencies": {
10 "apify": "^3.1.10",
11 "axios": "^1.5.0",
12 "cheerio": "^1.0.0-rc.12"
13 },
14 "scripts": {
15 "start": "node ./src/main.js",
16 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
17 },
18 "author": "It's not you it's me",
19 "license": "ISC"
20}
Developer
Maintained by Community
Actor metrics
- 3 monthly users
- 1 star
- 100.0% runs succeeded
- 16 days response time
- Created in Feb 2024
- Modified 7 months ago
Categories