Giter VIP home page Giter VIP logo

actor-scraper's Introduction

Apify Scrapers

This repository houses all of Apify generic actors that are used for simplified scraping using a pre-defined, schema validated UI input instead of the typical JSON input used in other actors.

Web Scraper

Web Scraper (apify/web-scraper) is a ready-made solution for scraping the web using the Chrome browser. It takes away all the work necessary to set up a browser for crawling, controls the browser automatically and produces machine readable results in several common formats.

Underneath, it uses the Puppeteer library to control the browser, but you don't need to worry about that. Using a simple web UI and a little of basic JavaScript, you can tweak it to serve almost any scraping need.

Puppeteer Scraper

Puppeteer Scraper (apify/puppeteer-scraper) is the most powerful scraper tool in our arsenal (aside from developing your own actors). It uses the Puppeteer library to programmatically control a headless Chrome browser and it can make it do almost anything. If using the Web Scraper does not cut it, Puppeteer Scraper is what you need.

Puppeteer is a Node.js library, so knowledge of Node.js and its paradigms is expected when working with the Puppeteer Scraper.

If you need either a faster, or a simpler tool, see the Cheerio Scraper for speed, or Web Scraper for simplicity.

Cheerio Scraper

Cheerio Scraper (apify/cheerio-scraper) is a ready-made solution for crawling the web using plain HTTP requests to retrieve HTML pages and then parsing and inspecting the HTML using the Cheerio library. It's blazing fast.

Cheerio is a server-side version of the popular jQuery library, that does not run in the browser, but instead constructs a DOM out of a HTML string and then provides the user with API to work with that DOM.

Cheerio Scraper is ideal for scraping websites that do not rely on client-side JavaScript to serve their content. It can be as much as 20 times faster than using a full browser solution such as Puppeteer.

Scraper Tools

A library that houses logic common to all the scrapers.

actor-scraper's People

Contributors

andreybykov avatar b4nan avatar davidjohnbarton avatar dependabot[bot] avatar drobnikj avatar fnesveda avatar jancurn avatar jbartadev avatar m-murasovs avatar metalwarrior665 avatar mnmkng avatar mstephen19 avatar mtrunkat avatar rixw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

actor-scraper's Issues

Tutorial improvements

  • The getting started guide doesn't mention how to enqueue requests manually, I found it somewhere in the SDK docs. Maybe giving an example of enqueueing requests manually in the getting started guide would be helpful for people starting out with writing a web-scraper.
  • Again about the context.enqueueRequest() function I was not sure if I can use it asynchronously or not? for example, is it ok to pass an async function to each():
subCategoriesSelector.each(async function() {
            // Suffix sub category link with a limit of 96
            var scLink = $(this).attr('href').replace('#', '?limit=96');
            //log.info(`SubCategory Link: ${scLink}`);
            await context.enqueueRequest({
                url:`${baseURL}/${scLink}`,
                userData: {
                    "label": "LIST"
                    }
                }
            );

Actor cannot be started with default input

If I make a task for this actor and hit the run button, I got an error message that Start URLs is not defined even there are two. Then I also have to set Max pages per crawl.

Evaluation failed when running: `npm run local`

Following the instructions to run locally returns the following error:

Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/".


    at <anonymous>:6:43
    at ExecutionContext.evaluateHandle (act-crawler/node_modules/puppeteer/lib/ExecutionContext.js:66:13)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Here's the RESULTS-1.json:

[
  {
    "id": 1,
    "label": "",
    "url": "https://news.ycombinator.com",
    "loadedUrl": "https://news.ycombinator.com/",
    "uniqueKey": "https://news.ycombinator.com",
    "referrerId": null,
    "requestedAt": "2017-12-28T09:34:17.387Z",
    "loadingStartedAt": "2017-12-28T09:34:18.609Z",
    "loadingFinishedAt": "2017-12-28T09:34:18.627Z",
    "responseStatus": 200,
    "responseHeaders": {
      "date": "Thu, 28 Dec 2017 09:34:18 GMT",
      "content-encoding": "gzip",
      "referrer-policy": "origin",
      "server": "cloudflare-nginx",
      "x-frame-options": "DENY",
      "content-type": "text/html; charset=utf-8",
      "status": "200",
      "x-xss-protection": "1; mode=block",
      "cache-control": "private; max-age=0",
      "content-security-policy": "default-src 'self'; script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/; frame-src 'self' https://www.google.com/recaptcha/; style-src 'self' 'unsafe-inline'; img-src 'self' 'unsafe-inline'",
      "strict-transport-security": "max-age=31556900",
      "cf-ray": "3d4385df4ee52fcf-MAA",
      "vary": "Accept-Encoding",
      "x-content-type-options": "nosniff"
    },
    "pageFunctionStartedAt": null,
    "pageFunctionFinishedAt": null,
    "type": "START_URL",
    "depth": 0,
    "pageFunctionResult": null,
    "interceptRequestData": null,
    "downloadedBytes": 196571,
    "willLoad": true,
    "queuePosition": "LAST",
    "errorInfo": [
      "Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/\".\n\n\n    at <anonymous>:6:43\n    at ExecutionContext.evaluateHandle (/private/tmp/act-crawler/node_modules/puppeteer/lib/ExecutionContext.js:66:13)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)",
      "Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/\".\n\n\n    at <anonymous>:6:43\n    at ExecutionContext.evaluateHandle (/private/tmp/act-crawler/node_modules/puppeteer/lib/ExecutionContext.js:66:13)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)",
      "Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/\".\n\n\n    at <anonymous>:6:43\n    at ExecutionContext.evaluateHandle (/private/tmp/act-crawler/node_modules/puppeteer/lib/ExecutionContext.js:66:13)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)",
      "Error: Evaluation failed: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/\".\n\n\n    at <anonymous>:6:43\n    at ExecutionContext.evaluateHandle (/private/tmp/act-crawler/node_modules/puppeteer/lib/ExecutionContext.js:66:13)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)"
    ],
    "retryCount": 3,
    "skipOutput": false,
    "outputSeqNum": 1
  }
]

Finish webhook URL

Hi,

Are there any chances we could get the crawler's webhook feature finishWebhookUrl implemented in this act?

Thanks

POST requests are treated as GET

Facing issues with the HTTP_REFERER header for an apify/web-scraper Task, I tried to dump $_SERVER on a test page after a POST request enqueued as

context.enqueueRequest(
    {
        url: "https://example.org/print_post_request.php",
        payload: "fname=lol&lname=wut",
        headers: {
            "Referer": "http://example.org"
        },
           method: "POST"
    }
);

but the output stated REQUEST_METHOD => GET. Then I checked setting the StartURL method to POST and the output was the same.

I conclude that POST settings are completely ignored by apify/web-scraper.

Add method to retire browser

If proxy IP doesn't work a user needs a way to retire the browser to obtain a new IP. This should wait for SessionPool to be added and this will simply invalidate the session.

Food for thought: How to use this actor for simple testing of scraping?

The legacy Crawler had one use case that doesn't seem to work nicely in this actor. Let's say you wanted to check if some webpage can be easily scraped or not. So you just created a new crawler, set the Start URL to the URL you wanted to check, click Run and see a screenshot of the page. When you do the same in this actor, the live view doesn't even show up and the actor finishes straight away. Is there some way to make this case work?

Allow using named storage

Two users already had a use-case where they want to store persistent data. Right now they have to use raw API which is not user friendly.

Request: Add email notification when complete

I would like to have the option to receive an email notification when the task is scheduled, starts and ends. I would prefer the default email address to be my account email but have a field or additional addresses.

Since you already have the email actor, the code already seems to be there.

Not able to access DOM using global window/document

Hi,

I am going through the documentation and on the below mentioned URL, you have written that window & document can be accessed. Now I don't want to inject jQuery as I can do all the stuff in Javascript only. But I am not able to access window/document

https://apify.com/apify/web-scraper#page-function

While document is returning object as below:

{
2021-01-25T13:54:00.587Z location: {
2021-01-25T13:54:00.587Z ancestorOrigins: {},
2021-01-25T13:54:00.588Z href: 'chrome-error://chromewebdata/',
2021-01-25T13:54:00.588Z origin: 'null',
2021-01-25T13:54:00.589Z protocol: 'chrome-error:',
2021-01-25T13:54:00.589Z host: 'chromewebdata',
2021-01-25T13:54:00.589Z hostname: 'chromewebdata',
2021-01-25T13:54:00.590Z port: '',
2021-01-25T13:54:00.590Z pathname: '/',
2021-01-25T13:54:00.591Z search: '',
2021-01-25T13:54:00.591Z hash: '',
2021-01-25T13:54:00.591Z assign: {},
2021-01-25T13:54:00.592Z reload: {},
2021-01-25T13:54:00.592Z replace: {},
2021-01-25T13:54:00.593Z toString: {}
2021-01-25T13:54:00.593Z }
2021-01-25T13:54:00.594Z }

While I was expecting the actual DOM object. Please help me out on this.

Upgrade Puppeteer to latest

The current version 0.13.0 is almost 3 months old. It would be good to move to the latest version 1.0.0 which would be more stable.

Add support for clickable divs and buttons

Currently only a tags are supported. Support for divs with href attribute is needed.
Is this something which is a quick fix? If someone can point in the right direction, then maybe I can add the fix and send out a PR.
Thanks

Can't remove a Link selector

When I remove the value of a Link selector ('a'), save the configuration and reload the page, the value is back again set to 'a'

Development mode breaks on request error

I have not researched this further, but it seems that when an error is thrown or some other issue happens in the browser, proxy is not correctly closed, or it tries to reconnect or I don't know what and it causes the scraper to get into an infinite loop of restarting browsers. More info in SDK slack channel.

Documentation improvements

Feedback from users:

  • Don't know what is input in the documentation about, there is no input in the UI that it is referring to, solved with custom data
  • Also I wasn't using the Pseudo URLs box but I wasn't sure if I should uncheck the 'Use Request Queue' checkbox or not in that case as I was adding to the request queue in the code.

Fix failing tests

Lately some of the integration tests were failing. We need to investigate why and fix the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.