@@ -61,16 +61,10 @@ def example_post_json():
6161 print ("\n === POST Request with JSON ===" )
6262
6363 try :
64- data = {
65- "username" : "test_user" ,
66- "email" : "test@example.com" ,
67- "age" : 25
68- }
64+ data = {"username" : "test_user" , "email" : "test@example.com" , "age" : 25 }
6965
7066 response = httpmorph .post (
71- "https://httpbin.org/post" ,
72- json = data ,
73- headers = {"Content-Type" : "application/json" }
67+ "https://httpbin.org/post" , json = data , headers = {"Content-Type" : "application/json" }
7468 )
7569
7670 print (f"Status: { response .status_code } " )
@@ -87,14 +81,11 @@ def example_custom_headers():
8781 headers = {
8882 "User-Agent" : "CustomBot/1.0" ,
8983 "Accept" : "application/json" ,
90- "X-Custom-Header" : "CustomValue"
84+ "X-Custom-Header" : "CustomValue" ,
9185 }
9286
9387 session = httpmorph .Session (browser = "chrome" )
94- response = session .get (
95- "https://httpbin.org/headers" ,
96- headers = headers
97- )
88+ response = session .get ("https://httpbin.org/headers" , headers = headers )
9889
9990 print (f"Status: { response .status_code } " )
10091 except NotImplementedError :
@@ -109,12 +100,11 @@ def example_rotating_fingerprint():
109100 for i in range (5 ):
110101 # Each request uses a different random browser fingerprint
111102 response = httpmorph .get (
112- "https://httpbin.org/get" ,
113- browser = "random" ,
114- rotate_fingerprint = True
103+ "https://httpbin.org/get" , browser = "random" , rotate_fingerprint = True
104+ )
105+ print (
106+ f"Request { i + 1 } - Status: { response .status_code } , JA3: { response .ja3_fingerprint } "
115107 )
116- print (f"Request { i + 1 } - Status: { response .status_code } , "
117- f"JA3: { response .ja3_fingerprint } " )
118108 except NotImplementedError :
119109 print ("Not yet implemented - C extension needs to be built" )
120110
@@ -136,19 +126,20 @@ def example_performance_test():
136126 fast_time = time .time () - start
137127
138128 print (f"httpmorph: { iterations } requests in { fast_time :.2f} s" )
139- print (f"Average: { fast_time / iterations * 1000 :.1f} ms per request" )
129+ print (f"Average: { fast_time / iterations * 1000 :.1f} ms per request" )
140130
141131 # Compare with requests
142132 try :
143133 import requests
134+
144135 start = time .time ()
145136 for _ in range (iterations ):
146137 requests .get (url )
147138 requests_time = time .time () - start
148139
149140 print (f"requests: { iterations } requests in { requests_time :.2f} s" )
150- print (f"Average: { requests_time / iterations * 1000 :.1f} ms per request" )
151- print (f"Speedup: { requests_time / fast_time :.2f} x faster" )
141+ print (f"Average: { requests_time / iterations * 1000 :.1f} ms per request" )
142+ print (f"Speedup: { requests_time / fast_time :.2f} x faster" )
152143 except ImportError :
153144 print ("requests library not installed for comparison" )
154145
0 commit comments