scrapeunblocker 0.19.0 → 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: 9ce0dab6107d17a3f97bf4dd1b987c7c959abae65f366b05bd517622c835c716
4
- data.tar.gz: aa000b55837243f345af4485ec03ca9de0520f52ba525aee19e3db49c18b0320
3
+ metadata.gz: e721cd3a4bd2f0664e561a87d99a53f6fd788b785dc70e12bab55658a46bed5e
4
+ data.tar.gz: 397e8c174c283dfb06b618cd5d0ef64100a611d1fa3c9b726e27de3b9d4e6aba
5
5
  SHA512:
6
- metadata.gz: 33d9fd7019a3fb09db76d43b8616159c3f25cbc499c4f5bbab86520cf9640373db592fc81855c08de45e0a9fe78ccf50932fc45bcd1b1f5e3cce409af3c02981
7
- data.tar.gz: 6995b58f61f1ed2fd87f0b905d1b3ef3de2101d52d7e432d158c471d79ed187da51c294e0aeb95163e23891fb8fa78b228ad69a1ae408816de28be59c1ba42d5
6
+ metadata.gz: cd6687ebda21ebd6a0d81c7c25c7250b76c4652bf99a180c174315816aa2b891f43ab65f4a3aac6b561754174de23d3504cda99f442f8d8aa54b6036a201155e
7
+ data.tar.gz: f24762c99473970762505f94fa02493f2b5c17f1aac2fe25b03d1bcd45ac45527144a12ad649fbc06cd61a3a44bdf592dc4f5ccbf19cdab9e105e3bed2f3adc6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 0.19.0 (2026-11-11)
4
10
 
5
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.
data/README.md CHANGED
@@ -273,6 +273,30 @@ p page.cookies
273
273
  puts page.proxy
274
274
  ```
275
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
+
276
300
  ## Images
277
301
 
278
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,
@@ -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.19.0"
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.19.0
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-11 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