Skip to content

Commit 055fe5b

Browse files
committed
chore: fixes
1 parent 1cf4593 commit 055fe5b

18 files changed

+324
-462
lines changed

examples/advanced_features.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def demo_browser_profiles():
2020
print("1. Browser Profiles")
2121
print("=" * 60)
2222

23-
browsers = ['chrome', 'firefox', 'safari', 'edge']
23+
browsers = ["chrome", "firefox", "safari", "edge"]
2424

2525
for browser in browsers:
2626
session = httpmorph.Session(browser=browser)
@@ -55,12 +55,9 @@ def demo_session_management():
5555
print("3. Session Management")
5656
print("=" * 60)
5757

58-
with httpmorph.Session(browser='chrome') as session:
58+
with httpmorph.Session(browser="chrome") as session:
5959
# Custom headers
60-
headers = {
61-
'X-Custom-Header': 'MyValue',
62-
'Accept': 'application/json'
63-
}
60+
headers = {"X-Custom-Header": "MyValue", "Accept": "application/json"}
6461

6562
response = session.get("https://api.github.com", headers=headers)
6663

@@ -95,14 +92,10 @@ def demo_performance_metrics():
9592

9693
import time
9794

98-
session = httpmorph.Session(browser='chrome')
95+
session = httpmorph.Session(browser="chrome")
9996

10097
# Multiple requests to same domain
101-
urls = [
102-
"https://example.com",
103-
"https://www.google.com",
104-
"https://api.github.com"
105-
]
98+
urls = ["https://example.com", "https://www.google.com", "https://api.github.com"]
10699

107100
print("\nSequential Requests:")
108101
for url in urls:
@@ -150,6 +143,7 @@ def main():
150143
except Exception as e:
151144
print(f"\n❌ Error: {e}")
152145
import traceback
146+
153147
traceback.print_exc()
154148

155149

examples/basic_usage.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)