11"""
2- 指纹伪装功能示例
2+ Fingerprint Spoofing Feature Examples
33
4- 演示如何使用 pydoll 的指纹伪装功能来防止浏览器指纹追踪。
4+ Demonstrates how to use pydoll's fingerprint spoofing features to prevent browser fingerprint tracking.
55"""
66
77import asyncio
1010
1111
1212async def basic_example ():
13- """基础示例:一键启用指纹伪装 """
14- print ("=== 基础示例:一键启用指纹伪装 ===" )
13+ """Basic example: Enable fingerprint spoofing with one click """
14+ print ("=== Basic Example: Enable Fingerprint Spoofing ===" )
1515
16- # 创建启用了指纹伪装的 Chrome 浏览器
16+ # Create Chrome browser with fingerprint spoofing enabled
1717 browser = Chrome (enable_fingerprint_spoofing = True )
1818
1919 async with browser :
20- # 启动浏览器
20+ # Start browser
2121 tab = await browser .start ()
2222
23- # 访问指纹检测网站
23+ # Visit fingerprint detection website
2424 await tab .go_to ("https://fingerprintjs.github.io/fingerprintjs/" )
2525
26- # 等待页面加载
26+ # Wait for page to load
2727 await asyncio .sleep (5 )
2828
29- # 获取指纹 ID
29+ # Get fingerprint ID
3030 try :
3131 fingerprint_element = await tab .find_element ("css" , ".visitor-id" )
3232 if fingerprint_element :
3333 fingerprint_id = await fingerprint_element .text
34- print (f"生成的指纹 ID: { fingerprint_id } " )
34+ print (f"Generated fingerprint ID: { fingerprint_id } " )
3535 except Exception as e :
36- print (f"获取指纹 ID 失败 : { e } " )
36+ print (f"Failed to get fingerprint ID : { e } " )
3737
38- # 截图保存结果
38+ # Take screenshot to save result
3939 try :
4040 await tab .take_screenshot ("fingerprint_result.png" )
41- print ("截图已保存为 fingerprint_result.png" )
41+ print ("Screenshot saved as fingerprint_result.png" )
4242 except Exception as e :
43- print (f"截图失败 : { e } " )
43+ print (f"Screenshot failed : { e } " )
4444
4545 await asyncio .sleep (3 )
4646
4747
4848async def custom_config_example ():
49- """高级示例:自定义指纹配置 """
50- print ("\n === 高级示例:自定义指纹配置 ===" )
49+ """Advanced example: Custom fingerprint configuration """
50+ print ("\n === Advanced Example: Custom Fingerprint Configuration ===" )
5151
52- # 创建自定义指纹配置
52+ # Create custom fingerprint configuration
5353 config = FingerprintConfig (
54- # 选择要伪装的功能
54+ # Select features to spoof
5555 spoof_user_agent = True ,
5656 spoof_screen = True ,
5757 spoof_hardware = True ,
@@ -60,15 +60,15 @@ async def custom_config_example():
6060 spoof_audio = True ,
6161 spoof_webrtc = True ,
6262
63- # 自定义设置
63+ # Custom settings
6464 browser_type = "chrome" ,
6565 os_type = "windows" ,
6666 device_type = "desktop" ,
6767 custom_languages = ["zh-CN" , "zh" , "en-US" , "en" ],
6868 custom_screen_resolution = (2560 , 1440 ),
6969 )
7070
71- # 创建浏览器实例
71+ # Create browser instance
7272 browser = Chrome (
7373 enable_fingerprint_spoofing = True ,
7474 fingerprint_config = config
@@ -77,12 +77,12 @@ async def custom_config_example():
7777 async with browser :
7878 tab = await browser .start ()
7979
80- # 访问浏览器信息检测网站
80+ # Visit browser information detection website
8181 await tab .go_to ("https://browserleaks.com/javascript" )
8282
8383 await asyncio .sleep (5 )
8484
85- # 获取并打印一些浏览器信息
85+ # Get and print some browser information
8686 try :
8787 user_agent = await tab .execute_script ("return navigator.userAgent" )
8888 print (f"User Agent: { user_agent } " )
@@ -97,28 +97,28 @@ async def custom_config_example():
9797 colorDepth: screen.colorDepth
9898 }
9999 """ )
100- print (f"屏幕信息 : { screen_info } " )
100+ print (f"Screen info : { screen_info } " )
101101 except Exception as e :
102- print (f"获取浏览器信息失败 : { e } " )
102+ print (f"Failed to get browser information : { e } " )
103103
104104 await asyncio .sleep (3 )
105105
106106
107107async def persistent_fingerprint_example ():
108- """持久化指纹示例:保存和重用指纹 """
109- print ("\n === 持久化指纹示例 ===" )
108+ """Persistent fingerprint example: Save and reuse fingerprints """
109+ print ("\n === Persistent Fingerprint Example ===" )
110110
111- # 创建指纹管理器
111+ # Create fingerprint manager
112112 fingerprint_manager = FingerprintManager ()
113113
114- # 配置持久化指纹
114+ # Configure persistent fingerprint
115115 config = FingerprintConfig (
116116 persist_fingerprint = True ,
117117 fingerprint_id = "my_persistent_fingerprint"
118118 )
119119
120- # 第一次使用:生成并保存指纹
121- print ("第一次访问:生成新指纹 " )
120+ # First use: Generate and save fingerprint
121+ print ("First visit: Generate new fingerprint " )
122122 browser1 = Chrome (
123123 enable_fingerprint_spoofing = True ,
124124 fingerprint_config = config
@@ -129,46 +129,46 @@ async def persistent_fingerprint_example():
129129 await tab .go_to ("https://amiunique.org/fingerprint" )
130130 await asyncio .sleep (5 )
131131
132- # 获取当前指纹
132+ # Get current fingerprint
133133 current_fingerprint = fingerprint_manager .current_fingerprint
134134 if current_fingerprint :
135- print (f"当前 User Agent: { current_fingerprint .user_agent } " )
136- print (f"当前平台 : { current_fingerprint .platform } " )
135+ print (f"Current User Agent: { current_fingerprint .user_agent } " )
136+ print (f"Current platform : { current_fingerprint .platform } " )
137137
138- # 第二次使用:加载已保存的指纹
139- print ("\n 第二次访问:使用相同的指纹 " )
138+ # Second use: Load saved fingerprint
139+ print ("\n Second visit: Use same fingerprint " )
140140
141- # 加载之前保存的指纹
141+ # Load previously saved fingerprint
142142 saved_fingerprint = fingerprint_manager .load_fingerprint ("my_persistent_fingerprint" )
143143 if saved_fingerprint :
144- print (f"加载的 User Agent: { saved_fingerprint .user_agent } " )
145- print (f"加载的平台 : { saved_fingerprint .platform } " )
144+ print (f"Loaded User Agent: { saved_fingerprint .user_agent } " )
145+ print (f"Loaded platform : { saved_fingerprint .platform } " )
146146
147- # 列出所有保存的指纹
147+ # List all saved fingerprints
148148 all_fingerprints = fingerprint_manager .list_fingerprints ()
149- print (f"\n 所有保存的指纹 : { list (all_fingerprints .keys ())} " )
149+ print (f"\n All saved fingerprints : { list (all_fingerprints .keys ())} " )
150150
151151
152152async def multiple_browsers_example ():
153- """多浏览器示例:同时运行多个不同指纹的浏览器 """
154- print ("\n === 多浏览器示例 ===" )
153+ """Multiple browsers example: Run multiple browsers with different fingerprints simultaneously """
154+ print ("\n === Multiple Browsers Example ===" )
155155
156- # 创建两个不同指纹的浏览器
156+ # Create two browsers with different fingerprints
157157 browser1 = Chrome (enable_fingerprint_spoofing = True )
158158 browser2 = Chrome (enable_fingerprint_spoofing = True )
159159
160160 async with browser1 , browser2 :
161- # 启动两个浏览器
161+ # Start both browsers
162162 tab1 = await browser1 .start ()
163163 tab2 = await browser2 .start ()
164164
165- # 都访问同一个指纹检测网站
165+ # Both visit the same fingerprint detection website
166166 await tab1 .go_to ("https://fingerprintjs.github.io/fingerprintjs/" )
167167 await tab2 .go_to ("https://fingerprintjs.github.io/fingerprintjs/" )
168168
169169 await asyncio .sleep (5 )
170170
171- # 获取两个浏览器的指纹 ID
171+ # Get fingerprint IDs from both browsers
172172 try :
173173 fp_element1 = await tab1 .find_element ("css" , ".visitor-id" )
174174 fp_element2 = await tab2 .find_element ("css" , ".visitor-id" )
@@ -177,24 +177,24 @@ async def multiple_browsers_example():
177177 fp_id1 = await fp_element1 .text
178178 fp_id2 = await fp_element2 .text
179179
180- print (f"浏览器 1 指纹 ID: { fp_id1 } " )
181- print (f"浏览器 2 指纹 ID: { fp_id2 } " )
180+ print (f"Browser 1 fingerprint ID: { fp_id1 } " )
181+ print (f"Browser 2 fingerprint ID: { fp_id2 } " )
182182
183183 if fp_id1 != fp_id2 :
184- print ("✓ 成功:两个浏览器生成了不同的指纹! " )
184+ print ("✓ Success: Two browsers generated different fingerprints! " )
185185 else :
186- print ("✗ 警告:两个浏览器的指纹相同 " )
186+ print ("✗ Warning: Both browsers have the same fingerprint " )
187187 except Exception as e :
188- print (f"获取指纹 ID 失败 : { e } " )
188+ print (f"Failed to get fingerprint ID : { e } " )
189189
190190 await asyncio .sleep (3 )
191191
192192
193193async def edge_browser_example ():
194- """Edge 浏览器示例 """
195- print ("\n === Edge 浏览器示例 ===" )
194+ """Edge browser example """
195+ print ("\n === Edge Browser Example ===" )
196196
197- # 创建启用了指纹伪装的 Edge 浏览器
197+ # Create Edge browser with fingerprint spoofing enabled
198198 browser = Edge (enable_fingerprint_spoofing = True )
199199
200200 async with browser :
@@ -203,7 +203,7 @@ async def edge_browser_example():
203203 await tab .go_to ("https://www.whatismybrowser.com/" )
204204 await asyncio .sleep (5 )
205205
206- # 检查浏览器识别
206+ # Check browser identification
207207 try :
208208 browser_info = await tab .execute_script ("""
209209 return {
@@ -213,37 +213,37 @@ async def edge_browser_example():
213213 }
214214 """ )
215215
216- print (f"Edge 浏览器信息 : { browser_info } " )
216+ print (f"Edge browser info : { browser_info } " )
217217 except Exception as e :
218- print (f"获取浏览器信息失败 : { e } " )
218+ print (f"Failed to get browser information : { e } " )
219219
220220 await asyncio .sleep (3 )
221221
222222
223223async def main ():
224- """运行所有示例 """
224+ """Run all examples """
225225 try :
226- # 运行基础示例
226+ # Run basic example
227227 await basic_example ()
228228
229- # 运行自定义配置示例
229+ # Run custom configuration example
230230 await custom_config_example ()
231231
232- # 运行持久化指纹示例
232+ # Run persistent fingerprint example
233233 await persistent_fingerprint_example ()
234234
235- # 运行多浏览器示例
235+ # Run multiple browsers example
236236 await multiple_browsers_example ()
237237
238- # 运行 Edge 浏览器示例
238+ # Run Edge browser example
239239 await edge_browser_example ()
240240
241241 except Exception as e :
242- print (f"运行示例时出错 : { e } " )
242+ print (f"Error running examples : { e } " )
243243 import traceback
244244 traceback .print_exc ()
245245
246246
247247if __name__ == "__main__" :
248- # 运行示例
248+ # Run examples
249249 asyncio .run (main ())
0 commit comments