Git Product home page Git Product logo

simple-scraping's Introduction

simple-scraping

Simple implementation for scraping website on Cloudflare Workers with HTMLRewriter.
You can get innerText using CSS Selector.

Cloudflare Workers上で動作する、HTMLRewriterを用いたスクレイピングツールのシンプルな実装。
CSSセレクタでinnerTextを取得できます。

Params / パラメータ

Param Description Example
url Target URL https://news.ycombinator.com/
selector CSS Selector .titleline a
attr Attribute Name href

Usage / 使い方

Request to /fetch endpoint with GET method. ?url and ?selector parameters are required. /fetchGETメソッドのリクエストを送ります。?url?selectorパラメータは必須です。

Example / 例

Get all story titles and links from HackerNews top page:
HackerNewsのトップページからストーリのタイトルとリンクを取得する:
Link

$ curl "https://simple-scraping.la1n.workers.dev/fetch?url=https://news.ycombinator.com/&selector=.titleline+>+a&attr=href"
{
  "innerText": [
    "Let me tell you about me Gear Fabrication Syndrome",
    "Yugoslavia's Digital Twin – When a country's internet domain outlives the nation",
    "Ceasing print publication of ACM journals and transactions",
    .....
  ],
  "attributes": [
    "https://weenoisemaker.com/blog/2023/10/21/gear-fabrication-syndrome.html",
    "https://www.thedial.world/issue-9/yugolsav-wars-yu-domain-history-icann",
    "https://www.acm.org/publications/ceasing-print",
    .....
  ]
}

Get all press release titles and links from Cabinet Office, Government of Japan:
内閣府の報道発表資料のタイトルとリンクを取得する:
Link

$ curl "https://simple-scraping.la1n.workers.dev/fetch?url=https://www.cao.go.jp/press/houdou.html&selector=.title+>+a&attr=href"

Deploy / デプロイ

$ wrangler deploy --minify ./index.js

Author

shinosaki

LICENSE

MIT

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.