Git Product home page Git Product logo

scrapy.js's Introduction

This readme doesn't represent the final touch.

Scrapy.js

A Web Scraping library for JavaScript built using BeautifulSoup4.

Overview of this library

First import the library using the script tag and then proceed to call the functions

<script src="https://sijey-praveen.github.io/scrapy.js/lib/scrapy.js"></script>

A common JavaScript syntax for using the Scrapy object looks like this:

var test = new Scrapy(url="https://example.com/", features="html.parser").findElement("*", attrs="*", get="*", callback=func())

Get Basic

new Scrapy() //creates an Scrapy object.

The Scrapy() object needs 2 necessary arguments to further next step.

  • url > The source url.

  • features > This may be the name of a specific parser ("lxml", "lxml-xml", "html.parser").

new Scrapy(url="https://example.com/", features="html.parser")

findElement()

  • The findElement() method is used to scrap the specific element from the given source url.

  • The findElement() method needs 3 necessary & 1 optional arguments to execute the program.

.findElement("div", attrs="class=hello", get="text", callback=(data)=> console.log(data))

element > the element you need to scrap.

attrs > you can specify element class and id or tags, if you need to specify class and id at the same time use ; to split it attrs="class=hello;id=hello" (optional).

get > the element value you need to return.

callback > A callback function is executed after the current effect is finished.

Notice

๐Ÿ˜œ You can use python print() method to log stuffs in console once you imported Scrapy.js in your html.

Example:

Scraping a word meaning from https://www.dictionary.com/

<!DOCTYPE html>
<meta charset="utf-8">
<html>
    <head>
        <script src="https://sijey-praveen.github.io/scrapy.js/lib/scrapy.js"></script>
    </head>
    <body>
        <script>
            var url = "https://www.dictionary.com/browse/hello"
            var meaning = new Scrapy(url=url, features="html.parser").findElement("div", attrs="class=css-10ul8x e1q3nk1v2", get="text", callback=(data)=> print(data))
        </script>                
    </body>
</html>

Console Output:

Image description

scrapy.js's People

Contributors

cj-praveen avatar

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.