scrapeunblocker 0.18.6 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5f215574b158552a6c50f4e9095b14c1da9184d4231784fe509bc3216fcdf24
4
- data.tar.gz: 59de9ec337fdd6e4335aa9181dd12b40b3d0c7019ec8eb4ab81c748b432bbc52
3
+ metadata.gz: e721cd3a4bd2f0664e561a87d99a53f6fd788b785dc70e12bab55658a46bed5e
4
+ data.tar.gz: 397e8c174c283dfb06b618cd5d0ef64100a611d1fa3c9b726e27de3b9d4e6aba
5
5
  SHA512:
6
- metadata.gz: b9f8529ae798dd9123110bd6a17b8ec3ce9b5223ec9935e338870d531d27f83aeff9fa8de51967d15281720e87000a963a3ac4c0094c1b54c0c93b660e772262
7
- data.tar.gz: ffc2a8a9a60e24bb08f16998740818a1518047622de48b6f976e6ea91ea971962b0b71eebdc15e65cdc9119e62cba96b1e55e146c382e5649373624d76bbed42
6
+ metadata.gz: cd6687ebda21ebd6a0d81c7c25c7250b76c4652bf99a180c174315816aa2b891f43ab65f4a3aac6b561754174de23d3504cda99f442f8d8aa54b6036a201155e
7
+ data.tar.gz: f24762c99473970762505f94fa02493f2b5c17f1aac2fe25b03d1bcd45ac45527144a12ad649fbc06cd61a3a44bdf592dc4f5ccbf19cdab9e105e3bed2f3adc6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.20.0 (2026-11-18)
4
+
5
+ - New `get_page_with_xhr(url, capture_xhr, steps:, proxy_country:)` for the API's `capture_xhr` parameter: the page is rendered in a real browser and every XHR/fetch response whose URL contains the fragment comes back as a `CapturedPage` (`html`, `xhr` - `XhrCall` objects with `url`, `method`, `status`, `content_type`, `body`, `body_omitted` and a `json` helper -, `xhr_truncated?`, `proxy`). Useful when a site renders from a JSON API that refuses direct requests.
6
+
7
+ No breaking changes.
8
+
9
+ ## 0.19.0 (2026-11-11)
10
+
11
+ - `serp` takes the new `full_urls:` keyword. Google gives out a results page's real links a few at a time, the last ones up to about 40 seconds after the search; by default the call returns sooner and a result whose link has not come yet has the site's home page as its `url` (or a Google redirect link). `full_urls: true` waits until every result has its real URL, so the call takes up to about 40 seconds longer. Billed the same. The parameter is only sent when true, so other requests are unchanged.
12
+
13
+ No breaking changes.
14
+
3
15
  ## 0.18.6 (2026-11-09)
4
16
 
5
17
  - Plugin method docs list the new response fields: Walmart product and search, Amazon product, Trustpilot reviews, Zillow property detail and Google Shopping. Taobao item methods document the catalogue key (`itemKey`). Requests are unchanged.
data/README.md CHANGED
@@ -182,6 +182,17 @@ serp["organic"].each { |r| puts [r["position"], r["title"], r["url"], r["date"],
182
182
  p serp["peopleAlsoAsk"], serp["relatedSearchLinks"], serp["knowledgeGraph"], serp["topStories"]
183
183
  ```
184
184
 
185
+ Google gives out a results page's real result links a few at a time, the last
186
+ ones up to about 40 seconds after the search. By default `serp` returns
187
+ sooner, and a result whose link has not come yet has the site's home page as
188
+ its `url` (or a Google redirect link when Google shows no site). Pass
189
+ `full_urls: true` to wait until (nearly) every result has its real URL: the
190
+ call then takes up to about 40 seconds longer and is billed the same.
191
+
192
+ ```ruby
193
+ serp = su.serp("best hiking boots", full_urls: true)
194
+ ```
195
+
185
196
  ## Google Local (Maps)
186
197
 
187
198
  ```ruby
@@ -262,6 +273,30 @@ p page.cookies
262
273
  puts page.proxy
263
274
  ```
264
275
 
276
+ ## The page's own API calls (XHR/fetch)
277
+
278
+ Many sites render from a JSON API the page calls itself, and that API often
279
+ refuses direct requests. `get_page_with_xhr` renders the page in a real browser
280
+ and returns every XHR/fetch response whose URL contains the fragment you pass,
281
+ in the order the page received them. Add `steps:` to make the page fire the
282
+ call (a search, "load more").
283
+
284
+ ```ruby
285
+ page = su.get_page_with_xhr(
286
+ "https://quotes.toscrape.com/scroll", "/api/quotes",
287
+ steps: [{ action: "scroll", value: "bottom" }, { action: "wait", value: 1500 }]
288
+ )
289
+ page.xhr.each do |call|
290
+ puts call.url, call.json["quotes"][0]["text"] if call.status == 200
291
+ end
292
+ ```
293
+
294
+ Each `XhrCall` has `url`, `method`, `status`, `content_type`, `body` (text) and
295
+ `body_omitted` (why there is no body). Up to 20 responses and 10 MB of bodies;
296
+ `page.xhr_truncated?` is true when more matched. When the site answers every
297
+ matching call with 403 or 429, the request fails like a block and
298
+ is not billed.
299
+
265
300
  ## Images
266
301
 
267
302
  ```ruby
@@ -128,6 +128,23 @@ module ScrapeUnblocker
128
128
  PageResult.from_hash(JSON.parse(body))
129
129
  end
130
130
 
131
+ # Fetch a URL and return the page's own XHR/fetch responses with it.
132
+ #
133
+ # Many sites render from a JSON API the page calls itself, and that API
134
+ # often refuses direct requests (the page signs each call). The page is
135
+ # rendered in a real browser and every XHR/fetch response whose URL
136
+ # contains +capture_xhr+ (e.g. "/api/search") comes back in the order the
137
+ # page received it: up to 20 responses and 10 MB of bodies. +steps+ (same
138
+ # format as #get_page_source) make the page fire the call. Returns a
139
+ # CapturedPage; a failed step raises ScrapeUnblocker::ValidationError whose
140
+ # body holds the step_failed JSON, including "xhr".
141
+ def get_page_with_xhr(url, capture_xhr, steps: nil, proxy_country: nil)
142
+ body = request("/getPageSource",
143
+ url: url, capture_xhr: capture_xhr, proxy_country: proxy_country,
144
+ steps: (steps ? JSON.generate(steps) : nil))[:body]
145
+ CapturedPage.from_hash(JSON.parse(body))
146
+ end
147
+
131
148
  # Run a Google search and return the parsed SERP as a Hash: "organic"
132
149
  # results and "topAds" / "bottomAds" (title, real url, description,
133
150
  # position, displayedUrl, domain, favicon, sitelinks; organic adds source,
@@ -137,12 +154,22 @@ module ScrapeUnblocker
137
154
  # localResults, shoppingResults and spellingCorrection (each empty or nil
138
155
  # when Google shows none).
139
156
  # +captcha_pause+ is kept for compatibility; the API ignores it.
140
- def serp(keyword, proxy_country: nil, pages_to_check: 1, wait_after_load: 0, captcha_pause: 0)
157
+ #
158
+ # +full_urls+ waits until Google gives out every result's real URL.
159
+ # Google releases a results page's links a few at a time, the last ones
160
+ # up to about 40 seconds after the search. Without it the call returns
161
+ # sooner, and a result whose link has not come yet has the site's home
162
+ # page as its "url" (or a Google redirect link when Google shows no
163
+ # site). With it, the call takes up to about 40 seconds longer. Billed
164
+ # the same.
165
+ def serp(keyword, proxy_country: nil, pages_to_check: 1, wait_after_load: 0, captcha_pause: 0,
166
+ full_urls: false)
141
167
  post_json("/serpApi",
142
168
  keyword: keyword, proxy_country: proxy_country,
143
169
  pages_to_check: pages_to_check,
144
170
  wait_after_load: (wait_after_load.zero? ? nil : wait_after_load),
145
- captcha_pause: (captcha_pause.zero? ? nil : captcha_pause))
171
+ captcha_pause: (captcha_pause.zero? ? nil : captcha_pause),
172
+ full_urls: (full_urls ? true : nil))
146
173
  end
147
174
 
148
175
  # Search Google Local (Maps) and return the businesses as a Hash.
@@ -66,4 +66,67 @@ module ScrapeUnblocker
66
66
  )
67
67
  end
68
68
  end
69
+
70
+ # One XHR/fetch response the page received (#get_page_with_xhr).
71
+ # +status+ is 0 when the request failed without a response; +body+ is nil
72
+ # when it was not returned, with +body_omitted+ saying why ("binary",
73
+ # "size_limit", "in_flight", "redirect", "unavailable" or "request_failed").
74
+ class XhrCall
75
+ attr_reader :url, :method, :status, :content_type, :body, :body_omitted
76
+
77
+ def initialize(url:, method:, status:, content_type: nil, body: nil, body_omitted: nil)
78
+ @url = url
79
+ @method = method
80
+ @status = status
81
+ @content_type = content_type
82
+ @body = body
83
+ @body_omitted = body_omitted
84
+ end
85
+
86
+ def self.from_hash(item)
87
+ new(
88
+ url: item["url"].to_s,
89
+ method: (item["method"] || "GET").to_s,
90
+ status: item["status"].to_i,
91
+ content_type: item["content_type"],
92
+ body: item["body"],
93
+ body_omitted: item["body_omitted"]
94
+ )
95
+ end
96
+
97
+ # The body parsed as JSON (raises JSON::ParserError / ArgumentError when it is not).
98
+ def json
99
+ raise ArgumentError, "no body (#{body_omitted || 'unavailable'})" if body.nil?
100
+
101
+ JSON.parse(body)
102
+ end
103
+ end
104
+
105
+ # A page plus the XHR/fetch responses it received (#get_page_with_xhr).
106
+ class CapturedPage
107
+ attr_reader :html, :xhr, :proxy, :raw
108
+
109
+ def initialize(html:, xhr:, xhr_truncated:, proxy:, raw:)
110
+ @html = html
111
+ @xhr = xhr
112
+ @xhr_truncated = xhr_truncated
113
+ @proxy = proxy
114
+ @raw = raw
115
+ end
116
+
117
+ # True when more responses matched than were returned.
118
+ def xhr_truncated?
119
+ @xhr_truncated
120
+ end
121
+
122
+ def self.from_hash(payload)
123
+ new(
124
+ html: payload["html"],
125
+ xhr: (payload["xhr"] || []).map { |item| XhrCall.from_hash(item) },
126
+ xhr_truncated: payload["xhr_truncated"] == true,
127
+ proxy: payload["proxy"],
128
+ raw: payload
129
+ )
130
+ end
131
+ end
69
132
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScrapeUnblocker
4
- VERSION = "0.18.6"
4
+ VERSION = "0.20.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrapeunblocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.6
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ScrapeUnblocker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-09 00:00:00.000000000 Z
11
+ date: 2026-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: JS-rendered pages that bypass Cloudflare, DataDome, PerimeterX and Akamai,
14
14
  plus Google SERP and 100+ ready-made site plugins (Amazon, Walmart, Zillow, Google