Class: WebScrapingAI::SelectedHTMLApi

Inherits:
Object
  • Object
show all
Defined in:
lib/webscraping_ai/api/selected_html_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ SelectedHTMLApi

Returns a new instance of SelectedHTMLApi.



19
20
21
# File 'lib/webscraping_ai/api/selected_html_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/webscraping_ai/api/selected_html_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#get_selected(url, opts = {}) ⇒ String

HTML of a selected page area by URL and CSS selector Returns HTML of a selected page area by URL and CSS selector. Useful if you don’t want to do the HTML parsing on your side.

Parameters:

  • url (String)

    URL of the target page.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :selector (String)

    CSS selector (null by default, returns whole page HTML)

  • :headers (Hash<String, String>)

    HTTP headers to pass to the target page. Can be specified either via a nested query parameter (…&amp;headers&#x3D;value1&amp;headers&#x3D;&#x3D;value2) or as a JSON encoded object (…&amp;headers&#x3D;&quot;value1&quot;, &quot;Another&quot;: &quot;value2&quot;).

  • :timeout (Integer)

    Maximum web page retrieval time in ms. Increase it in case of timeout errors (10000 by default, maximum is 30000). (default to 10000)

  • :js (Boolean)

    Execute on-page JavaScript using a headless browser (true by default). (default to true)

  • :js_timeout (Integer)

    Maximum JavaScript rendering time in ms. Increase it in case if you see a loading indicator instead of data on the target page. (default to 2000)

  • :proxy (String)

    Type of proxy, use residential proxies if your site restricts traffic from datacenters (datacenter by default). Note that residential proxy requests are more expensive than datacenter, see the pricing page for details. (default to ‘datacenter’)

  • :country (String)

    Country of the proxy to use (US by default). Only available on Startup and Custom plans. (default to ‘us’)

  • :device (String)

    Type of device emulation. (default to ‘desktop’)

  • :error_on_404 (Boolean)

    Return error on 404 HTTP status on the target page (false by default). (default to false)

  • :error_on_redirect (Boolean)

    Return error on redirect on the target page (false by default). (default to false)

  • :js_script (String)

    Custom JavaScript code to execute on the target page.

Returns:

  • (String)


38
39
40
41
# File 'lib/webscraping_ai/api/selected_html_api.rb', line 38

def get_selected(url, opts = {})
  data, _status_code, _headers = get_selected_with_http_info(url, opts)
  data
end

#get_selected_multiple(url, opts = {}) ⇒ Array<String>

HTML of multiple page areas by URL and CSS selectors Returns HTML of multiple page areas by URL and CSS selectors. Useful if you don’t want to do the HTML parsing on your side.

Parameters:

  • url (String)

    URL of the target page.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :selectors (Array<String>)

    Multiple CSS selectors (null by default, returns whole page HTML)

  • :headers (Hash<String, String>)

    HTTP headers to pass to the target page. Can be specified either via a nested query parameter (…&amp;headers&#x3D;value1&amp;headers&#x3D;&#x3D;value2) or as a JSON encoded object (…&amp;headers&#x3D;&quot;value1&quot;, &quot;Another&quot;: &quot;value2&quot;).

  • :timeout (Integer)

    Maximum web page retrieval time in ms. Increase it in case of timeout errors (10000 by default, maximum is 30000). (default to 10000)

  • :js (Boolean)

    Execute on-page JavaScript using a headless browser (true by default). (default to true)

  • :js_timeout (Integer)

    Maximum JavaScript rendering time in ms. Increase it in case if you see a loading indicator instead of data on the target page. (default to 2000)

  • :proxy (String)

    Type of proxy, use residential proxies if your site restricts traffic from datacenters (datacenter by default). Note that residential proxy requests are more expensive than datacenter, see the pricing page for details. (default to ‘datacenter’)

  • :country (String)

    Country of the proxy to use (US by default). Only available on Startup and Custom plans. (default to ‘us’)

  • :device (String)

    Type of device emulation. (default to ‘desktop’)

  • :error_on_404 (Boolean)

    Return error on 404 HTTP status on the target page (false by default). (default to false)

  • :error_on_redirect (Boolean)

    Return error on redirect on the target page (false by default). (default to false)

  • :js_script (String)

    Custom JavaScript code to execute on the target page.

Returns:

  • (Array<String>)


163
164
165
166
# File 'lib/webscraping_ai/api/selected_html_api.rb', line 163

def get_selected_multiple(url, opts = {})
  data, _status_code, _headers = get_selected_multiple_with_http_info(url, opts)
  data
end

#get_selected_multiple_with_http_info(url, opts = {}) ⇒ Array<(Array<String>, Integer, Hash)>

HTML of multiple page areas by URL and CSS selectors Returns HTML of multiple page areas by URL and CSS selectors. Useful if you don&#39;t want to do the HTML parsing on your side.

Parameters:

  • url (String)

    URL of the target page.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :selectors (Array<String>)

    Multiple CSS selectors (null by default, returns whole page HTML)

  • :headers (Hash<String, String>)

    HTTP headers to pass to the target page. Can be specified either via a nested query parameter (…&amp;headers&#x3D;value1&amp;headers&#x3D;&#x3D;value2) or as a JSON encoded object (…&amp;headers&#x3D;&quot;value1&quot;, &quot;Another&quot;: &quot;value2&quot;).

  • :timeout (Integer)

    Maximum web page retrieval time in ms. Increase it in case of timeout errors (10000 by default, maximum is 30000). (default to 10000)

  • :js (Boolean)

    Execute on-page JavaScript using a headless browser (true by default). (default to true)

  • :js_timeout (Integer)

    Maximum JavaScript rendering time in ms. Increase it in case if you see a loading indicator instead of data on the target page. (default to 2000)

  • :proxy (String)

    Type of proxy, use residential proxies if your site restricts traffic from datacenters (datacenter by default). Note that residential proxy requests are more expensive than datacenter, see the pricing page for details. (default to ‘datacenter’)

  • :country (String)

    Country of the proxy to use (US by default). Only available on Startup and Custom plans. (default to ‘us’)

  • :device (String)

    Type of device emulation. (default to ‘desktop’)

  • :error_on_404 (Boolean)

    Return error on 404 HTTP status on the target page (false by default). (default to false)

  • :error_on_redirect (Boolean)

    Return error on redirect on the target page (false by default). (default to false)

  • :js_script (String)

    Custom JavaScript code to execute on the target page.

Returns:

  • (Array<(Array<String>, Integer, Hash)>)

    Array<String> data, response status code and response headers



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/webscraping_ai/api/selected_html_api.rb', line 184

def get_selected_multiple_with_http_info(url, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SelectedHTMLApi.get_selected_multiple ...'
  end
  # verify the required parameter 'url' is set
  if @api_client.config.client_side_validation && url.nil?
    fail ArgumentError, "Missing the required parameter 'url' when calling SelectedHTMLApi.get_selected_multiple"
  end
  if @api_client.config.client_side_validation && !opts[:'timeout'].nil? && opts[:'timeout'] > 30000
    fail ArgumentError, 'invalid value for "opts[:"timeout"]" when calling SelectedHTMLApi.get_selected_multiple, must be smaller than or equal to 30000.'
  end

  if @api_client.config.client_side_validation && !opts[:'timeout'].nil? && opts[:'timeout'] < 1
    fail ArgumentError, 'invalid value for "opts[:"timeout"]" when calling SelectedHTMLApi.get_selected_multiple, must be greater than or equal to 1.'
  end

  if @api_client.config.client_side_validation && !opts[:'js_timeout'].nil? && opts[:'js_timeout'] > 20000
    fail ArgumentError, 'invalid value for "opts[:"js_timeout"]" when calling SelectedHTMLApi.get_selected_multiple, must be smaller than or equal to 20000.'
  end

  if @api_client.config.client_side_validation && !opts[:'js_timeout'].nil? && opts[:'js_timeout'] < 1
    fail ArgumentError, 'invalid value for "opts[:"js_timeout"]" when calling SelectedHTMLApi.get_selected_multiple, must be greater than or equal to 1.'
  end

  allowable_values = ["datacenter", "residential"]
  if @api_client.config.client_side_validation && opts[:'proxy'] && !allowable_values.include?(opts[:'proxy'])
    fail ArgumentError, "invalid value for \"proxy\", must be one of #{allowable_values}"
  end
  allowable_values = ["us", "gb", "de", "it", "fr", "ca", "es", "ru", "jp", "kr"]
  if @api_client.config.client_side_validation && opts[:'country'] && !allowable_values.include?(opts[:'country'])
    fail ArgumentError, "invalid value for \"country\", must be one of #{allowable_values}"
  end
  allowable_values = ["desktop", "mobile", "tablet"]
  if @api_client.config.client_side_validation && opts[:'device'] && !allowable_values.include?(opts[:'device'])
    fail ArgumentError, "invalid value for \"device\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/selected-multiple'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'url'] = url
  query_params[:'selectors'] = @api_client.build_collection_param(opts[:'selectors'], :multi) if !opts[:'selectors'].nil?
  query_params[:'headers'] = opts[:'headers'] if !opts[:'headers'].nil?
  query_params[:'timeout'] = opts[:'timeout'] if !opts[:'timeout'].nil?
  query_params[:'js'] = opts[:'js'] if !opts[:'js'].nil?
  query_params[:'js_timeout'] = opts[:'js_timeout'] if !opts[:'js_timeout'].nil?
  query_params[:'proxy'] = opts[:'proxy'] if !opts[:'proxy'].nil?
  query_params[:'country'] = opts[:'country'] if !opts[:'country'].nil?
  query_params[:'device'] = opts[:'device'] if !opts[:'device'].nil?
  query_params[:'error_on_404'] = opts[:'error_on_404'] if !opts[:'error_on_404'].nil?
  query_params[:'error_on_redirect'] = opts[:'error_on_redirect'] if !opts[:'error_on_redirect'].nil?
  query_params[:'js_script'] = opts[:'js_script'] if !opts[:'js_script'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Array<String>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['api_key']

  new_options = opts.merge(
    :operation => :"SelectedHTMLApi.get_selected_multiple",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SelectedHTMLApi#get_selected_multiple\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_selected_with_http_info(url, opts = {}) ⇒ Array<(String, Integer, Hash)>

HTML of a selected page area by URL and CSS selector Returns HTML of a selected page area by URL and CSS selector. Useful if you don&#39;t want to do the HTML parsing on your side.

Parameters:

  • url (String)

    URL of the target page.

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :selector (String)

    CSS selector (null by default, returns whole page HTML)

  • :headers (Hash<String, String>)

    HTTP headers to pass to the target page. Can be specified either via a nested query parameter (…&amp;headers&#x3D;value1&amp;headers&#x3D;&#x3D;value2) or as a JSON encoded object (…&amp;headers&#x3D;&quot;value1&quot;, &quot;Another&quot;: &quot;value2&quot;).

  • :timeout (Integer)

    Maximum web page retrieval time in ms. Increase it in case of timeout errors (10000 by default, maximum is 30000). (default to 10000)

  • :js (Boolean)

    Execute on-page JavaScript using a headless browser (true by default). (default to true)

  • :js_timeout (Integer)

    Maximum JavaScript rendering time in ms. Increase it in case if you see a loading indicator instead of data on the target page. (default to 2000)

  • :proxy (String)

    Type of proxy, use residential proxies if your site restricts traffic from datacenters (datacenter by default). Note that residential proxy requests are more expensive than datacenter, see the pricing page for details. (default to ‘datacenter’)

  • :country (String)

    Country of the proxy to use (US by default). Only available on Startup and Custom plans. (default to ‘us’)

  • :device (String)

    Type of device emulation. (default to ‘desktop’)

  • :error_on_404 (Boolean)

    Return error on 404 HTTP status on the target page (false by default). (default to false)

  • :error_on_redirect (Boolean)

    Return error on redirect on the target page (false by default). (default to false)

  • :js_script (String)

    Custom JavaScript code to execute on the target page.

Returns:

  • (Array<(String, Integer, Hash)>)

    String data, response status code and response headers



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/webscraping_ai/api/selected_html_api.rb', line 59

def get_selected_with_http_info(url, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SelectedHTMLApi.get_selected ...'
  end
  # verify the required parameter 'url' is set
  if @api_client.config.client_side_validation && url.nil?
    fail ArgumentError, "Missing the required parameter 'url' when calling SelectedHTMLApi.get_selected"
  end
  if @api_client.config.client_side_validation && !opts[:'timeout'].nil? && opts[:'timeout'] > 30000
    fail ArgumentError, 'invalid value for "opts[:"timeout"]" when calling SelectedHTMLApi.get_selected, must be smaller than or equal to 30000.'
  end

  if @api_client.config.client_side_validation && !opts[:'timeout'].nil? && opts[:'timeout'] < 1
    fail ArgumentError, 'invalid value for "opts[:"timeout"]" when calling SelectedHTMLApi.get_selected, must be greater than or equal to 1.'
  end

  if @api_client.config.client_side_validation && !opts[:'js_timeout'].nil? && opts[:'js_timeout'] > 20000
    fail ArgumentError, 'invalid value for "opts[:"js_timeout"]" when calling SelectedHTMLApi.get_selected, must be smaller than or equal to 20000.'
  end

  if @api_client.config.client_side_validation && !opts[:'js_timeout'].nil? && opts[:'js_timeout'] < 1
    fail ArgumentError, 'invalid value for "opts[:"js_timeout"]" when calling SelectedHTMLApi.get_selected, must be greater than or equal to 1.'
  end

  allowable_values = ["datacenter", "residential"]
  if @api_client.config.client_side_validation && opts[:'proxy'] && !allowable_values.include?(opts[:'proxy'])
    fail ArgumentError, "invalid value for \"proxy\", must be one of #{allowable_values}"
  end
  allowable_values = ["us", "gb", "de", "it", "fr", "ca", "es", "ru", "jp", "kr"]
  if @api_client.config.client_side_validation && opts[:'country'] && !allowable_values.include?(opts[:'country'])
    fail ArgumentError, "invalid value for \"country\", must be one of #{allowable_values}"
  end
  allowable_values = ["desktop", "mobile", "tablet"]
  if @api_client.config.client_side_validation && opts[:'device'] && !allowable_values.include?(opts[:'device'])
    fail ArgumentError, "invalid value for \"device\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/selected'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'url'] = url
  query_params[:'selector'] = opts[:'selector'] if !opts[:'selector'].nil?
  query_params[:'headers'] = opts[:'headers'] if !opts[:'headers'].nil?
  query_params[:'timeout'] = opts[:'timeout'] if !opts[:'timeout'].nil?
  query_params[:'js'] = opts[:'js'] if !opts[:'js'].nil?
  query_params[:'js_timeout'] = opts[:'js_timeout'] if !opts[:'js_timeout'].nil?
  query_params[:'proxy'] = opts[:'proxy'] if !opts[:'proxy'].nil?
  query_params[:'country'] = opts[:'country'] if !opts[:'country'].nil?
  query_params[:'device'] = opts[:'device'] if !opts[:'device'].nil?
  query_params[:'error_on_404'] = opts[:'error_on_404'] if !opts[:'error_on_404'].nil?
  query_params[:'error_on_redirect'] = opts[:'error_on_redirect'] if !opts[:'error_on_redirect'].nil?
  query_params[:'js_script'] = opts[:'js_script'] if !opts[:'js_script'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json', 'text/html'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'String'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['api_key']

  new_options = opts.merge(
    :operation => :"SelectedHTMLApi.get_selected",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SelectedHTMLApi#get_selected\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end