forked from lexiforest/curl_cffi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
38 lines (30 loc) · 986 Bytes
/
example.py
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
from io import BytesIO
from curl_cffi import Curl, CurlInfo, CurlOpt, requests
def main_curl():
buffer = BytesIO()
c = Curl()
c.setopt(CurlOpt.CUSTOMREQUEST, b"GET")
c.setopt(CurlOpt.URL, b"https://tls.browserleaks.com/json")
c.setopt(CurlOpt.WRITEDATA, buffer)
c.perform()
body = buffer.getvalue()
print("NO impersonate:")
print(body.decode())
print("")
buffer = BytesIO()
c.setopt(CurlOpt.WRITEDATA, buffer)
c.setopt(CurlOpt.URL, b"https://httpbin.org/headers")
c.impersonate("chrome99")
c.setopt(CurlOpt.HTTPHEADER, [b"User-Agent: Curl/impersonate"])
c.perform()
body = buffer.getvalue()
print("with impersonate:")
print(body.decode())
c.close()
def main_requests():
r = requests.get("https://tls.browserleaks.com/json")
print(r.json())
r = requests.get("https://tls.browserleaks.com/json", impersonate="chrome101")
print(r.json())
if __name__ == "__main__":
main_requests()