Gathering detailed insights and metrics for @petrpatek/got-scraping
Gathering detailed insights and metrics for @petrpatek/got-scraping
npm install @petrpatek/got-scraping
Typescript
Module System
Node Version
NPM Version
65.7
Supply Chain
96.1
Quality
74
Maintenance
100
Vulnerability
99.3
License
Total Downloads
663
Last Day
1
Last Week
2
Last Month
14
Last Year
59
Minified
Minified + Gzipped
Latest Version
0.0.1-dev.2
Package Id
@petrpatek/got-scraping@0.0.1-dev.2
Unpacked Size
19.23 kB
Size
6.44 kB
File Count
11
NPM Version
6.14.11
Node Version
12.21.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-60%
2
Compared to previous week
Last month
600%
14
Compared to previous month
Last year
-53.5%
59
Compared to previous year
Got Scraping is a small but powerful got extension that allows you to send browser-like requests with only a little configuration seamlessly and with a single function call. Got is a widely use and powerful client that provides extensibility and customization. Sending browser-like requests is essential in the web scraping industry to blend in with the website traffic. You can read more about the mimics here.
With the increasing popularity of web scraping, it is becoming more important to blend in with the typical internet traffic. This package implements multiple mimics to make GET requests similar to browsers. Thanks to the included header-generator
package, you can choose various browsers from different operating systems and devices. The header-generator
package generates all the headers for you so that you can focus on the important stuff.
But the got-scraping
doesn't stop here. The got-scraping
package also tries to mimic the full request fingerprint, including the correct HTTP protocol and TLS ciphers.
Proxies are essential in the web scraping industry. Another goal of this package is to simplify the usage of HTTP
and HTTPS
proxies. All you have to do is pass the proxyUrl
option.
There is one more good news for loyal got
users. This package is modified got instance using handlers so that you can use the got interface as always. We've added just a few extras.
The Got Scraping package's primary goal is to make the document GET request look like a real browser made it. The crucial part of this process is to send browser-like headers. This process is outsourced to the header-generator
package, allowing you to customize browsers, devices, languages, and operating systems to generate the request headers. The generation of the request headers is based on real-world data, and the algorithm is periodically updated. For more information, see the header-generator
README.
This package can only generate all the standard attributes. There still might be site-specific attributes that you need to add. One of those attributes you might want to add is the referer
header. Referer header might add more credibility to your request and hence reduce the blocking. Check out more info about the referer
header here. Please bear in mind that these headers are made for GET requests for HTML documents. If you want to make POST requests or GET requests for any other content type, you should alter these headers according to your needs. You can do so by passing a headers option or writing a custom got handler.
The second colossal factor is using the same HTTP version as browsers. Most modern browsers use HTTP v2, so using it when the server supports it takes you one more step further to look like a browser. Luckily you don't have to care about the server HTTP version support since got automatically handles ALPN protocol negotiation and uses the HTTP v2 only if it is supported.
The last step is to have a browser-like TLS suite and ciphers. According to our research, the cipher TLS_AES_256_GCM_SHA384
is used among all modern browsers. We use this cipher as a default one. However, feel free to change it.
This package should provide a solid start for your browser request emulation process. All websites are built differently, and some of them might require some additional special care.
Got Scraping package makes using proxies with your requests ridiculously easy. It supports multiple variations of connections through HTTP1 and HTTP2 proxies to HTTP1 and HTTP2 servers. You can see the supported variations below. All you have to do is pass a valid proxyUrl
option.
Proxy type | Proxy HTTP version | Agents |
---|---|---|
https | http2 | http2, https, http |
https | http1 | http2, https |
http | http1 | http2, https, http |
The proxy type and proxy HTTP version is a type of connection to a proxy. The agents are supported connections from the proxy to the target, let's say, a website.
We strongly recommend using Node 12+ because of the compatible TLS ciphers we use to emulate the browser. However, this package is compatible with Node 10+.
1$ npm install got-scraping
These examples should help you to grasp the concept of the got-scraping
package quickly.
1const gotScraping = require('got-scraping'); 2 3gotScraping 4 .get('https://apify.com') 5 .then( ({ body }) => console.log(body))
1const gotScraping = require('got-scraping'); 2 3gotScraping({ 4 url: 'https://apify.com', 5 proxyUrl: 'http://myproxy.com:1234', 6}) 7 .then(({ body }) => console.log(body)); 8
By passing options:
1const response = await gotScraping({ 2 url: 'https://apify.com/', 3 headers: { 4 'user-agent': 'test', 5 }, 6});
You can check out how to override request headers using handlers in the original got repo under the instances section.
1const response = await gotScraping({ 2 url: 'https://api.apify.com/v2/browser-info', 3 headerGeneratorOptions:{ 4 browsers:[ 5 { 6 name: 'chrome', 7 minVersion: 87, 8 maxVersion: 89 9 } 10 ], 11 devices: ['desktop'], 12 languages: ['de-DE', 'en-US'], 13 operatingSystems: ['windows', 'linux'] 14 } 15});
You can get JSON
body with this package too, but please bear in mind that the request header generation is done specifically for HTML
content type. You might want to alter the generated headers to match the browser ones.
1const response = await gotScraping({ 2 responseType: 'json', 3 url: 'https://api.apify.com/v2/browser-info', 4 ciphers: undefined, 5});
Got scraping package is built using got.extend
functionality and supports all of the got API. On top of that, it adds few more options to the got once and then passes them by a handler to the got
context object. This package also alters got defaults to be more scraping friendly.
1const SCRAPING_DEFAULT_OPTIONS = { 2 // Most of the new browsers use HTTP2 3 http2: true, 4 https: { 5 // We usually don't want to fail because of SSL errors. 6 // We want the content. 7 rejectUnauthorized: false, 8 }, 9 // This would fail all of 404, 403 responses. 10 // We usually don't want to consider these as errors. 11 // We want to take some action after this. 12 throwHttpErrors: false, 13 // Node js uses different TLS ciphers by default. 14 ciphers: getCiphersBasedOnNode(), 15 // We need to have browser-like headers to blend in. 16 useHeaderGenerator: true, 17};
proxyUrl
- Url of HTTPS or HTTP based proxy. HTTP2 proxies are supported.
useHeaderGenerator
- Turns on the generation of the browser-like header. By default, it is set to true
.
headerGeneratorOptions
- See the @TODO: proper link (HeaderGeneratroOptions)[https://github.com/apify/header-generator]
This section covers possible errors that might happen due to different site implementations.
RequestError: Client network socket disconnected before secure TLS connection was established
- Try changing the ciphers parameter to either undefined
or a custom value.
No vulnerabilities found.
No security vulnerabilities found.