![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
cheerio-httpcli
Advanced tools
Node.jsでWEBページのスクレイピングを行う際に必要となる文字コードの変換とHTMLのパースを行った後のオブジェクトを取得できるHTTPクライアントモジュールです。
WEBページの取得にはrequest、文字コードの変換にはiconv、HTMLのパースにはcheerioを使用しています。
cheerioはHTMLをjQueryライクにパースしてくれるモジュールです。パース後のオブジェクトを格納する変数名を「$」にすると、$('title').text()
のようなjQueryそのままの形で要素の情報を取得できます。
npm install cheerio-httpcli
url
で指定したWEBページをGETメソッドで取得し、文字コードの変換とHTMLパースを行いcallback
に返します。
callback
には以下の3つの引数が渡されます。
cheerio.load()
でHTMLコンテンツをパースしたオブジェクトresponse
オブジェクトGET時にパラメータを付加する場合は、get-param
に連想配列で指定します。
var client = require('cheerio-httpcli');
// Googleで「node.js」について検索する。
client.fetch('http://www.google.com/search', { q: 'node.js' }, function (err, $, res) {
// レスポンスヘッダを参照
console.log(res.headers);
// HTMLタイトルを表示
console.log($('title').text());
// リンク一覧を表示
$('a').each(function (idx) {
console.log($(this).attr('href'));
});
});
同梱の「example.js」はGoogle検索結果の一覧を取得するサンプルです。参考にしてください。
requestモジュールで使用するリクエストヘッダ情報の連想配列です。デフォルトではUser-Agent
のみIE9の情報を指定しています。
requestモジュールで指定するタイムアウト情報です。デフォルトでは30秒となっています。
サーバーとの通信にgzip転送を使用するかどうかを真偽値で指定します。デフォルトはtrue
(gzip転送する)です。
<head>
タグのcharset情報を参照しています。charsetで指定された文字コードとWEBページの実際の文字コードが異なる場合は変換エラーとなります。fetch()
のcallbackの第3引数にrequestモジュールのresponse
オブジェクトを追加MIT licenseで配布します。
© 2013 ktty1220
0.1.2 (2013-09-06)
fetch()
のcallbackの第3引数にrequestモジュールのresponse
オブジェクトを追加FAQs
http client module with cheerio & iconv(-lite) & promise
The npm package cheerio-httpcli receives a total of 467 weekly downloads. As such, cheerio-httpcli popularity was classified as not popular.
We found that cheerio-httpcli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.