{"id":13426044,"url":"https://github.com/HarryStevens/jquery-scrape","last_synced_at":"2025-03-15T20:31:55.992Z","repository":{"id":34922897,"uuid":"190423122","full_name":"HarryStevens/jquery-scrape","owner":"HarryStevens","description":"Use jQuery as your selection engine on the result of an HTTP/HTTPS request.","archived":false,"fork":false,"pushed_at":"2022-12-09T05:19:11.000Z","size":83,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T19:49:55.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/jquery-scrape","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HarryStevens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-05T15:43:49.000Z","updated_at":"2022-06-06T22:51:02.000Z","dependencies_parsed_at":"2023-01-15T10:27:16.581Z","dependency_job_id":null,"html_url":"https://github.com/HarryStevens/jquery-scrape","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fjquery-scrape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fjquery-scrape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fjquery-scrape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarryStevens%2Fjquery-scrape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HarryStevens","download_url":"https://codeload.github.com/HarryStevens/jquery-scrape/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790939,"owners_count":20348378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T00:01:25.094Z","updated_at":"2025-03-15T20:31:50.982Z","avatar_url":"https://github.com/HarryStevens.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jquery-scrape\nUse jQuery as your selection engine on an HTTP request's response. [![Build Status](https://travis-ci.org/HarryStevens/jquery-scrape.svg?branch=master)](https://travis-ci.org/HarryStevens/jquery-scrape)\n\n## Installation\n```bash\nnpm i jquery-scrape -S\n```\n\n## Usage\njquery-scrape is a convenience wrapper for [request](https://github.com/request/request) and [cheerio](https://github.com/cheeriojs/cheerio). With almost no code, you can make an HTTP request and get back a jQuery selection engine. Here's a working example that you can run in your terminal:\n```js\nrequire(\"jquery-scrape\")(\"https://www.example.com/\", $ =\u003e {\n\n  // Get the inner HTML of the DOM's body element.\n  const html = $(\"body\").html();\n  console.log(html);\n\n  // Get the href attribute of an anchor tag.\n  const href = $(\"a\").attr(\"href\");\n  console.log(href);\n\n  // Traverse through each paragraph...\n  $(\"p\").each((i, p) =\u003e {\n    // ...and get its text.\n    const text = $(p).text().trim();\n    console.log(text);\n  });\n\n});\n```\n\nOr suppose you want to scrape a table and save the result as JSON. Suppose the table is structured like [the one in this repo's test directory](https://github.com/HarryStevens/jquery-scrape/blob/master/test/test.html):\n```html\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eNumber\u003c/th\u003e\n      \u003cth\u003eValue\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eFoo\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eBar\u003c/td\u003e\n    \u003c/tr\u003e      \n  \u003c/tbody\u003e\n\u003c/table\u003e\n```\n\nScrape it like so:\n```js\nrequire(\"jquery-scrape\")(\"https://raw.githubusercontent.com/HarryStevens/jquery-scrape/master/test/test.html\", $ =\u003e {\n\n  let columns = [];\n  $(\"th\").each((i, th) =\u003e {\n    columns.push($(th).text());\n  });\n\n  let data = [];\n  const rows = $(\"tbody tr\");\n  console.log(`Found ${rows.length} rows. Scraping them...`);\n  rows.each((rowIndex, row) =\u003e {\n    let object = {};\n    $(row).find(\"td\").each((cellIndex, cell) =\u003e {\n      object[columns[cellIndex]] = $(cell).text();\n    });\n    console.log(`${((rowIndex + 1) / rows.length * 100).toFixed(1)}%`);\n    data.push(object);\n  });\n\n  console.log(\"Writing file: data.json\");\n  fs.writeFile(\"data.json\", JSON.stringify(data), err =\u003e {\n    if (err) throw err;\n    console.log(\"File saved.\");\n    process.exit();\n  });\n\n});\n```\n\n## Tests\n```bash\nnpm test\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHarryStevens%2Fjquery-scrape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHarryStevens%2Fjquery-scrape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHarryStevens%2Fjquery-scrape/lists"}