Repository navigation
Expand file tree
/
Copy pathweb.py
More file actions
3240 lines (2929 loc) · 103 KB
/
Copy pathweb.py
File metadata and controls
3240 lines (2929 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
from typing import Dict, List, Union, Optional
from typing_extensions import Literal
import httpx
from ..types import (
web_scrape_params,
web_search_params,
web_answers_params,
web_map_urls_params,
web_screenshot_params,
web_web_crawl_md_params,
web_extract_styleguide_params,
web_extract_competitors_params,
)
from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from .._utils import maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from .._base_client import make_request_options
from ..types.web_scrape_response import WebScrapeResponse
from ..types.web_search_response import WebSearchResponse
from ..types.web_answers_response import WebAnswersResponse
from ..types.web_map_urls_response import WebMapURLsResponse
from ..types.web_screenshot_response import WebScreenshotResponse
from ..types.web_web_crawl_md_response import WebWebCrawlMdResponse
from ..types.web_extract_styleguide_response import WebExtractStyleguideResponse
from ..types.web_extract_competitors_response import WebExtractCompetitorsResponse
__all__ = ["WebResource", "AsyncWebResource"]
class WebResource(SyncAPIResource):
@cached_property
def with_raw_response(self) -> WebResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/context-dot-dev/context-python-sdk#accessing-raw-response-data-eg-headers
"""
return WebResourceWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> WebResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/context-dot-dev/context-python-sdk#with_streaming_response
"""
return WebResourceWithStreamingResponse(self)
def answers(
self,
*,
task: str,
controls: web_answers_params.Controls | Omit = omit,
json_format: Dict[str, object] | Omit = omit,
mode: Literal["fast", "ultra"] | Omit = omit,
policies: SequenceNotStr[str] | Omit = omit,
tags: SequenceNotStr[str] | Omit = omit,
timeout_opts: web_answers_params.TimeoutOpts | Omit = omit,
zdr: Literal["enabled", "disabled"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> WebAnswersResponse:
"""
Research a task across the live web and Context.dev's company and people data,
and get the answer in the JSON shape you provide, with the URLs it used. `fast`
(10 credits) suits short lookups; `ultra` (100 credits, the default) reads more
sources for deeper research.
Args:
task: What to research, in plain language, up to 2000 characters. Include domains or
URLs to focus the research.
controls: Limit which sites the research can search, read, and cite.
json_format: Example of the answer object to return, not a JSON Schema. Up to 8 levels deep,
500 values, and 16,000 characters. Values that cannot be found come back as
`null`. Defaults to `{ "result": "" }`.
mode: `fast` prioritizes speed and adds extra verification for people and companies;
`ultra` searches and reads more sources for deeper research. Defaults to
`ultra`.
policies: Access policy IDs to apply; each URL must pass all of them. Requires access
policies enabled for your organization; otherwise returns
`ACCESS_POLICIES_NOT_ENABLED`.
tags: Labels for this request. Filter usage and request logs by them in the dashboard
or with `GET /org/logs`.
timeout_opts: Request deadline and what to return when it passes.
zdr: `enabled` turns on zero data retention. Returns 403 `ZDR_NOT_ENABLED` unless
your organization has ZDR.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/web/answers",
body=maybe_transform(
{
"task": task,
"controls": controls,
"json_format": json_format,
"mode": mode,
"policies": policies,
"tags": tags,
"timeout_opts": timeout_opts,
"zdr": zdr,
},
web_answers_params.WebAnswersParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=WebAnswersResponse,
)
def extract_competitors(
self,
*,
domain: str,
num_competitors: int | Omit = omit,
tags: SequenceNotStr[str] | Omit = omit,
timeout_opts: web_extract_competitors_params.TimeoutOpts | Omit = omit,
zdr: Literal["enabled", "disabled"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> WebExtractCompetitorsResponse:
"""
Find a company's direct competitors from its website and web search results.
Each competitor comes with a confidence level and the search results behind it.
Args:
domain: Company domain, such as `stripe.com`. Full URLs are reduced to their domain.
num_competitors: Exact number of direct competitors to return.
tags: Comma-separated labels for this request, such as `production,team-alpha`. Filter
usage and request logs by them.
timeout_opts: Request deadline and what to return when it passes.
zdr: `enabled` turns on zero data retention. Returns 403 `ZDR_NOT_ENABLED` unless
your organization has ZDR.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/web/competitors",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"domain": domain,
"num_competitors": num_competitors,
"tags": tags,
"timeout_opts": timeout_opts,
"zdr": zdr,
},
web_extract_competitors_params.WebExtractCompetitorsParams,
),
),
cast_to=WebExtractCompetitorsResponse,
)
def extract_styleguide(
self,
*,
color_scheme: Literal["light", "dark"] | Omit = omit,
direct_url: str | Omit = omit,
domain: str | Omit = omit,
max_age_ms: Optional[int] | Omit = omit,
policies: SequenceNotStr[str] | Omit = omit,
tags: SequenceNotStr[str] | Omit = omit,
timeout_opts: web_extract_styleguide_params.TimeoutOpts | Omit = omit,
zdr: Literal["enabled", "disabled"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> WebExtractStyleguideResponse:
"""
Extract a website's design system: colors, typography, spacing, shadows, button
and card styles, and downloadable font files. Every component style includes
ready-to-use CSS.
Args:
color_scheme: Emulate a light or dark color scheme. Each scheme is cached separately.
direct_url: Exact page URL to analyze. Provide either `domain` or `directUrl`, not both.
domain: Domain to analyze, such as `stripe.com`. Provide either `domain` or `directUrl`,
not both.
max_age_ms: Maximum age of a cached result, in milliseconds. `0` always fetches fresh.
Defaults to 90 days (7776000000 ms). Values above 1 year (31536000000 ms) are
capped at 1 year.
policies: Comma-separated access policy IDs to apply; each URL must pass all of them.
Requires access policies enabled for your organization; otherwise returns
`ACCESS_POLICIES_NOT_ENABLED`.
tags: Comma-separated labels for this request, such as `production,team-alpha`. Filter
usage and request logs by them.
timeout_opts: Request deadline and what to return when it passes.
zdr: `enabled` turns off request logs and traces and keeps request and response
content out of usage logs. Brand data and hosted assets may still be stored.
Returns 403 `ZDR_NOT_ENABLED` unless your organization has ZDR.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/web/styleguide",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"color_scheme": color_scheme,
"direct_url": direct_url,
"domain": domain,
"max_age_ms": max_age_ms,
"policies": policies,
"tags": tags,
"timeout_opts": timeout_opts,
"zdr": zdr,
},
web_extract_styleguide_params.WebExtractStyleguideParams,
),
),
cast_to=WebExtractStyleguideResponse,
)
def map_urls(
self,
*,
domain: str,
exclude_url_regex: str | Omit = omit,
headers: Dict[str, str] | Omit = omit,
include_subdomains: bool | Omit = omit,
max_links: int | Omit = omit,
policies: SequenceNotStr[str] | Omit = omit,
search: str | Omit = omit,
sitemap_url: str | Omit = omit,
tags: SequenceNotStr[str] | Omit = omit,
timeout_opts: web_map_urls_params.TimeoutOpts | Omit = omit,
url_regex: str | Omit = omit,
zdr: Literal["enabled", "disabled"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> WebMapURLsResponse:
"""
Map up to 100,000 URLs on a domain, with titles, descriptions, keywords, and
language when available. Filter with regex patterns, or rank by topic with
`search` for 1 extra credit. Newly discovered URLs can lack metadata.
Args:
domain: Domain to map, such as `stripe.com`.
exclude_url_regex: Leave out URLs matching this regex, even when they match `urlRegex`.
headers: HTTP headers to send to the target site. Requests with headers skip the cache.
include_subdomains: Include URLs on subdomains.
max_links: Maximum number of URLs to return.
policies: Comma-separated access policy IDs to apply; each URL must pass all of them.
Requires access policies enabled for your organization; otherwise returns
`ACCESS_POLICIES_NOT_ENABLED`.
search: Filter URLs by a topic or phrase, most relevant first.
sitemap_url: Fetch this sitemap instead of discovering sitemaps. Must belong to the domain or
a subdomain.
tags: Comma-separated labels for this request, such as `production,team-alpha`. Filter
usage and request logs by them.
timeout_opts: Request deadline and what to return when it passes.
url_regex: Only return URLs matching this regex. Only matches count toward `maxLinks`.
zdr: `enabled` turns on zero data retention. Returns 403 `ZDR_NOT_ENABLED` unless
your organization has ZDR.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/web/urls",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"domain": domain,
"exclude_url_regex": exclude_url_regex,
"headers": headers,
"include_subdomains": include_subdomains,
"max_links": max_links,
"policies": policies,
"search": search,
"sitemap_url": sitemap_url,
"tags": tags,
"timeout_opts": timeout_opts,
"url_regex": url_regex,
"zdr": zdr,
},
web_map_urls_params.WebMapURLsParams,
),
),
cast_to=WebMapURLsResponse,
)
def scrape(
self,
*,
formats: web_scrape_params.Formats,
url: str,
highlights_params: web_scrape_params.HighlightsParams | Omit = omit,
image_params: web_scrape_params.ImageParams | Omit = omit,
json_params: web_scrape_params.JsonParams | Omit = omit,
markdown_params: web_scrape_params.MarkdownParams | Omit = omit,
max_age_ms: int | Omit = omit,
parse_params: web_scrape_params.ParseParams | Omit = omit,
policies: SequenceNotStr[str] | Omit = omit,
product_params: web_scrape_params.ProductParams | Omit = omit,
screenshot_params: web_scrape_params.ScreenshotParams | Omit = omit,
shared_params: web_scrape_params.SharedParams | Omit = omit,
tags: SequenceNotStr[str] | Omit = omit,
timeout_opts: web_scrape_params.TimeoutOpts | Omit = omit,
zdr: Literal["enabled", "disabled"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> WebScrapeResponse:
"""
Turn any URL into Markdown, HTML, a screenshot, images, raw bytes, parsed
fields, product data, highlights, or schema-matched JSON in one request. Choose
the outputs in `formats`; each one succeeds or fails on its own. Handles PDF,
Word, Excel, PowerPoint, and 40 other file formats.
Args:
formats: Outputs to return. Set at least one to `true`.
url: Public HTTP or HTTPS URL to scrape.
highlights_params: Query for the `highlights` output. Required when `formats.highlights` is `true`,
and allowed only then.
image_params: Options for the `images` output. Requires `formats.images: true`.
json_params: Schema and instructions for the `json` output. Required when `formats.json` is
`true`, and allowed only then.
markdown_params: Options for the `markdown` output. Requires `formats.markdown: true`.
max_age_ms: Maximum age of a cached result, in milliseconds. `0` always fetches fresh.
Defaults to 3 days (259200000 ms). Maximum: 1 year (31536000000 ms).
parse_params: Custom rules or a prebuilt parser for the `parsed` output. Required when
`formats.parse` is `true`, and allowed only then.
policies: Access policy IDs to apply; each URL must pass all of them. Requires access
policies enabled for your organization; otherwise returns
`ACCESS_POLICIES_NOT_ENABLED`.
product_params: Options for the `product` output. Requires `formats.product: true`.
screenshot_params: Options for the `screenshot` output. Requires `formats.screenshot: true`.
shared_params: Browser and content settings shared by all outputs.
tags: Labels for this request. Filter usage and request logs by them in the dashboard
or with `GET /org/logs`.
timeout_opts: Request deadline and what to return when it passes.
zdr: `enabled` turns on zero data retention. Returns 403 `ZDR_NOT_ENABLED` unless
your organization has ZDR.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/web/scrape",
body=maybe_transform(
{
"formats": formats,
"url": url,
"highlights_params": highlights_params,
"image_params": image_params,
"json_params": json_params,
"markdown_params": markdown_params,
"max_age_ms": max_age_ms,
"parse_params": parse_params,
"policies": policies,
"product_params": product_params,
"screenshot_params": screenshot_params,
"shared_params": shared_params,
"tags": tags,
"timeout_opts": timeout_opts,
"zdr": zdr,
},
web_scrape_params.WebScrapeParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=WebScrapeResponse,
)
def screenshot(
self,
*,
clear_popups: bool | Omit = omit,
color_scheme: Literal["light", "dark"] | Omit = omit,
country: Literal[
"ad",
"ae",
"af",
"ag",
"ai",
"al",
"am",
"ao",
"ar",
"at",
"au",
"aw",
"az",
"ba",
"bb",
"bd",
"be",
"bf",
"bg",
"bh",
"bi",
"bj",
"bm",
"bn",
"bo",
"bq",
"br",
"bs",
"bw",
"by",
"bz",
"ca",
"cd",
"cf",
"cg",
"ch",
"ci",
"cl",
"cm",
"cn",
"co",
"cr",
"cv",
"cw",
"cy",
"cz",
"de",
"dj",
"dk",
"dm",
"do",
"dz",
"ec",
"ee",
"eg",
"es",
"et",
"fi",
"fj",
"fr",
"ga",
"gb",
"gd",
"ge",
"gf",
"gg",
"gh",
"gm",
"gn",
"gp",
"gq",
"gr",
"gt",
"gu",
"gw",
"gy",
"hk",
"hn",
"hr",
"ht",
"hu",
"id",
"ie",
"il",
"im",
"in",
"iq",
"ir",
"is",
"it",
"je",
"jm",
"jo",
"jp",
"ke",
"kg",
"kh",
"kn",
"kr",
"kw",
"ky",
"kz",
"la",
"lb",
"lc",
"lk",
"lr",
"ls",
"lt",
"lu",
"lv",
"ly",
"ma",
"mc",
"md",
"me",
"mf",
"mg",
"mk",
"ml",
"mm",
"mn",
"mo",
"mq",
"mr",
"mt",
"mu",
"mv",
"mw",
"mx",
"my",
"mz",
"na",
"nc",
"ne",
"ng",
"ni",
"nl",
"no",
"np",
"nz",
"om",
"pa",
"pe",
"pf",
"pg",
"ph",
"pk",
"pl",
"pr",
"ps",
"pt",
"py",
"qa",
"re",
"ro",
"rs",
"ru",
"rw",
"sa",
"sc",
"sd",
"se",
"sg",
"si",
"sk",
"sl",
"sm",
"sn",
"so",
"sr",
"ss",
"st",
"sv",
"sx",
"sy",
"sz",
"tc",
"td",
"tg",
"th",
"tj",
"tl",
"tm",
"tn",
"tr",
"tt",
"tw",
"tz",
"ua",
"ug",
"us",
"uy",
"uz",
"vc",
"ve",
"vg",
"vi",
"vn",
"ye",
"yt",
"za",
"zm",
"zw",
]
| Omit = omit,
direct_url: str | Omit = omit,
domain: str | Omit = omit,
full_screenshot: Literal["true", "false"] | Omit = omit,
handle_cookie_popup: bool | Omit = omit,
headers: Dict[str, str] | Omit = omit,
max_age_ms: Optional[int] | Omit = omit,
page: Literal["login", "signup", "blog", "careers", "pricing", "terms", "privacy", "contact"] | Omit = omit,
scroll_offset: Optional[int] | Omit = omit,
tags: SequenceNotStr[str] | Omit = omit,
timeout_opts: web_screenshot_params.TimeoutOpts | Omit = omit,
viewport: web_screenshot_params.Viewport | Omit = omit,
wait_for_ms: Optional[int] | Omit = omit,
zdr: Literal["enabled", "disabled"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> WebScreenshotResponse:
"""
Capture a screenshot of a website's home page, a page type such as pricing, or
an exact URL. Returns the visible viewport, a scroll slice, or the full page.
Args:
clear_popups: Dismiss cookie banners and close other popups and overlays before capture.
color_scheme: Emulate a light or dark color scheme.
country: Country to fetch from, as an ISO 3166-1 alpha-2 code.
direct_url: Exact URL to capture, such as `https://example.com/pricing`. Provide either
`domain` or `directUrl`, not both.
domain: Domain to capture, such as `stripe.com`. Provide either `domain` or `directUrl`,
not both.
full_screenshot: Capture the full scrollable page instead of only the viewport.
handle_cookie_popup: Dismiss cookie consent banners before capture.
headers: HTTP headers to send to the target origin, such as
`headers[Authorization]=Bearer token`. Requests with headers skip the cache and
return the image as a data URL.
max_age_ms: Maximum age of a cached result, in milliseconds. `0` always fetches fresh.
Defaults to 1 day (86400000 ms). Maximum: 30 days (2592000000 ms).
page: Capture this type of page instead of the home page. Context.dev finds it among
the domain's links, in 30 languages. Only with `domain`.
scroll_offset: Return the viewport-sized slice of the full page that starts this many pixels
from the top. Step by the viewport height, such as `0`, `1080`, `2160`, to walk
a long page. The last slice can be shorter. Overrides `fullScreenshot`.
tags: Comma-separated labels for this request, such as `production,team-alpha`. Filter
usage and request logs by them.
timeout_opts: Request deadline and what to return when it passes.
viewport: Browser viewport size in pixels.
wait_for_ms: Time to wait after the page loads before capturing, in milliseconds. `0` waits
500 ms. `timeoutOpts.milliseconds` must be at least `waitForMs` plus 10000 ms,
or the request fails with `TIMEOUT_TOO_SHORT_FOR_WAIT`.
zdr: `enabled` turns on zero data retention. Returns 403 `ZDR_NOT_ENABLED` unless
your organization has ZDR.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/web/screenshot",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"clear_popups": clear_popups,
"color_scheme": color_scheme,
"country": country,
"direct_url": direct_url,
"domain": domain,
"full_screenshot": full_screenshot,
"handle_cookie_popup": handle_cookie_popup,
"headers": headers,
"max_age_ms": max_age_ms,
"page": page,
"scroll_offset": scroll_offset,
"tags": tags,
"timeout_opts": timeout_opts,
"viewport": viewport,
"wait_for_ms": wait_for_ms,
"zdr": zdr,
},
web_screenshot_params.WebScreenshotParams,
),
),
cast_to=WebScreenshotResponse,
)
def search(
self,
*,
query: str,
country: Literal[
"af",
"al",
"dz",
"as",
"ad",
"ao",
"ai",
"aq",
"ag",
"ar",
"am",
"aw",
"au",
"at",
"az",
"bs",
"bh",
"bd",
"bb",
"by",
"be",
"bz",
"bj",
"bm",
"bt",
"bo",
"ba",
"bw",
"bv",
"br",
"io",
"bn",
"bg",
"bf",
"bi",
"kh",
"cm",
"ca",
"cv",
"ky",
"cf",
"td",
"cl",
"cn",
"cx",
"cc",
"co",
"km",
"cg",
"cd",
"ck",
"cr",
"ci",
"hr",
"cu",
"cy",
"cz",
"dk",
"dj",
"dm",
"do",
"ec",
"eg",
"sv",
"gq",
"er",
"ee",
"et",
"fk",
"fo",
"fj",
"fi",
"fr",
"gf",
"pf",
"tf",
"ga",
"gm",
"ge",
"de",
"gh",
"gi",
"gr",
"gl",
"gd",
"gp",
"gu",
"gt",
"gn",
"gw",
"gy",
"ht",
"hm",
"va",
"hn",
"hk",
"hu",
"is",
"in",
"id",
"ir",
"iq",
"ie",
"il",
"it",
"jm",
"jp",
"jo",
"kz",
"ke",
"ki",
"kp",
"kr",
"kw",
"kg",
"la",
"lv",
"lb",
"ls",
"lr",
"ly",
"li",
"lt",
"lu",
"mo",
"mk",
"mg",
"mw",
"my",
"mv",
"ml",
"mt",
"mh",
"mq",
"mr",
"mu",
"yt",
"mx",
"fm",
"md",
"mc",
"mn",
"ms",
"ma",
"mz",
"mm",
"na",
"nr",
"np",
"nl",
"an",
"nc",
"nz",
"ni",
"ne",
"ng",
"nu",
"nf",
"mp",
"no",
"om",
"pk",
"pw",
"ps",
"pa",
"pg",
"py",
"pe",
"ph",
"pn",
"pl",
"pt",
"pr",
"qa",
"re",
"ro",
"ru",
"rw",
"sh",
"kn",
"lc",
"pm",
"vc",
"ws",
"sm",
"st",
"sa",
"sn",
"rs",
"sc",
"sl",
"sg",
"sk",