### Install fpgen package with pip Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Install the fpgen library using the pip package manager. This command downloads and installs the necessary files to use the library. ```bash pip install fpgen ``` -------------------------------- ### Trace Probability for Multiple Targets in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Shows how to use 'fpgen.trace' with a list or tuple for the 'target' parameter to get probability distributions for multiple variables simultaneously, filtered by conditions like GPU vendor. ```python >>> fpgen.trace( ... target=('browser', 'os'), ... gpu={'vendor': 'Google Inc. (Intel)'} ... ) {'browser': [, , , , , ], 'os': [, , , ]} ``` -------------------------------- ### Generate Specific Headers using Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Explains using the 'target' parameter with 'fpgen.generate' to get only the HTTP header data from a generated fingerprint. ```python >>> fpgen.generate(target='headers') {'accept': '*/*', 'accept-encoding': 'gzip, deflate, br, zstd', 'accept-language': 'en-US,en;q=0.9', 'priority': 'u=1, i', 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', 'sec-ch-ua-mobile': null, 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'sec-gpc': null, 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36'} ``` -------------------------------- ### Query Possible Values for Target in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Shows how to use 'fpgen.query' to retrieve a list of all possible values for a given target variable, such as listing all known browser types. ```python >>> fpgen.query('browser') ['Chrome', 'Edge', 'Firefox', 'Opera', 'Safari', 'Samsung Internet', 'Yandex Browser'] ``` -------------------------------- ### Generate Specific Headers using Shortcut in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Shows the 'generate_target' shortcut as an alternative way to generate specific data fields like HTTP headers. ```python >>> fpgen.generate_target('headers') {'accept': '*/*', 'accept-encoding': 'gzip, deflate, br, zstd', 'accept-language': 'en-GB,en;q=0.9,en-US;q=0.8,sk;q=0.7', 'priority': 'u=1, i', 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', 'sec-ch-ua-mobile': null, 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site', 'sec-gpc': null, 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'} ``` -------------------------------- ### Display fpgen CLI commands Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Show the available commands and options for the fpgen command-line interface. This provides help on how to use the CLI for model management. ```bash Usage: python -m fpgen [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: decompress Decompress model files for speed efficiency (will take 100mb+) fetch Fetch the latest model from GitHub recompress Compress model files after running decompress remove Remove all downloaded and/or extracted model files ``` -------------------------------- ### Trace Probability Distribution for Target in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Explains how to use 'fpgen.trace' to calculate and view the probability distribution of a specific target variable (like 'browser') given certain conditions (like 'os' is 'Windows'). ```python >>> fpgen.trace(target='browser', os='Windows') [, , , , , ] ``` -------------------------------- ### Generate fingerprint with fpgen (simple) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Import the fpgen library and generate a fingerprint directly using the top-level generate function. You can specify conditions like browser and operating system as keyword arguments. ```python >>> import fpgen >>> fpgen.generate(browser='Chrome', os='Windows') ``` -------------------------------- ### Query Possible Values for Nested Target in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Demonstrates using 'fpgen.query' with a dot-separated path to query the possible values for a nested target variable, such as the 'maxTouchPoints' property within the 'navigator' object. ```python >>> fpgen.query('navigator.maxTouchPoints') # Dot seperated path [0, 1, 2, 5, 6, 9, 10, 17, 20, 40, 256] ``` -------------------------------- ### Trace Probability using Generator Object in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Illustrates how the 'trace' method can also be called on an instance of the 'fpgen.Generator' class, allowing tracing probabilities based on the conditions set during the object's initialization. ```python >>> gen = fpgen.Generator(os='ChromeOS') >>> gen.trace(target='browser') [] ``` -------------------------------- ### Fetch latest fpgen model Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Fetch the latest model data required by fpgen from GitHub. This is run automatically on the first import or every 5 weeks, but can be triggered manually. ```bash fpgen fetch ``` -------------------------------- ### Decompress fpgen model for speed Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Decompress the downloaded model files to significantly improve generation speed (up to 10-50x faster). Note that this requires additional storage space (100mb+). ```bash fpgen decompress ``` -------------------------------- ### Generate Specific Nested Target (User-Agent) in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Demonstrates generating a specific nested data field, like the User-Agent string within headers, while filtering by OS and browser using dot notation for the target path. ```python >>> fpgen.generate( ... os='Windows', ... browser='Chrome', ... # Nested targets must be seperated by dots: ... target='headers.user-agent' ... ) 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0' ``` -------------------------------- ### Filter fpgen generation (kwargs) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Generate a fingerprint while applying specific criteria for multiple data fields, such as operating system, browser, and GPU vendor, by passing them as keyword arguments to the generate function. ```python # Only generate fingerprints with Windows, Chrome, and Intel GPU: >>> fpgen.generate( ... os='Windows', ... browser='Chrome', ... gpu={'vendor': 'Google Inc. (Intel)'} ... ) ``` -------------------------------- ### Filter fpgen generation (custom lambda, window size) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Apply custom filters using lambda functions for multiple nested fields within a dictionary, such as setting acceptable ranges for window dimensions (outerWidth and outerHeight). ```python # Set allowed ranges for outerWidth & outerHeight: >>> fpgen.generate( ... window={ ... 'outerWidth': lambda width: 1000 <= width <= 2000, ... 'outerHeight': lambda height: 500 <= height <= 1500 ... } ... ) ``` -------------------------------- ### Read TraceResult Object Properties in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Explains how to access the probability and value attributes of individual 'TraceResult' objects returned by the 'fpgen.trace' method, demonstrating how to extract specific data points from the results. ```python >>> chrome = fpgen.trace(target='browser', os='ChromeOS')[0] >>> chrome.probability 1.0 >>> chrome.value 'Chrome' ``` -------------------------------- ### Filter fpgen generation (dictionary) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Generate a fingerprint by passing all filtering criteria as a single dictionary to the generate function. This is an alternative way to specify conditions compared to using keyword arguments. ```python >>> fpgen.generate({ ... 'os': 'Windows', ... 'browser': 'Chrome', ... 'gpu': {'vendor': 'Google Inc. (Intel)'}, ... }) ``` -------------------------------- ### Generate Specific Nested Target (TLS Fingerprint) in Python Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Shows how to generate a specific nested data field, such as the TLS fingerprint data, filtered by a specific browser like Firefox, using dot notation for the target path. ```python >>> fpgen.generate( ... browser='Firefox', ... target='network.tls.scrapfly_fp' ... ) {'version': '772', 'ch_ciphers': '4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-156-157-47-53', 'ch_extensions': '0-5-10-11-13-16-23-27-28-34-35-43-45-51-65037-65281', 'groups': '4588-29-23-24-25-256-257', 'points': '0', 'compression': '0', 'supported_versions': '772-771', 'supported_protocols': 'h2-http11', 'key_shares': '4588-29-23', 'psk': '1', 'signature_algs': '1027-1283-1539-2052-2053-2054-1025-1281-1537-515-513', 'early_data': '0'} ``` -------------------------------- ### Generate fingerprint with fpgen (Generator object) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Create a Generator object to set default filters that will be inherited by subsequent generate calls. This is useful for applying common conditions across multiple generations. ```python >>> gen = fpgen.Generator(browser='Chrome') # Filter by Chrome >>> gen.generate(os='Windows') # Generate Windows & Chrome fingerprints ``` -------------------------------- ### Filter fpgen generation (custom function, window size) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Apply a custom filter using a dedicated function for an entire dictionary field, such as the window object. The function receives the dictionary and should return True if the entire dictionary meets the criteria. ```python def window_filter(window): if not (1000 <= window['outerWidth'] <= 2000): return False if not (500 <= window['outerHeight'] <= 1500): return False return True fpgen.generate(window=window_filter) ``` -------------------------------- ### Filter fpgen generation (multiple constraints) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Specify multiple acceptable values for a single data field by providing a tuple of options. The generator will select one value from the provided tuple for that field. ```python >>> fpgen.generate({ ... 'os': ('Windows', 'MacOS'), ... 'browser': ('Firefox', 'Chrome'), ... }) ``` -------------------------------- ### Filter fpgen generation (custom lambda, dot path) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Apply a custom filter using a lambda function for a nested data field by specifying its path using dot notation as the dictionary key. The lambda receives the field's value. ```python # Or, just pass a dot seperated path to client.browser.major: >>> fpgen.generate({'client.browser.major': lambda ver: int(ver) >= 130}) ``` -------------------------------- ### Filter fpgen generation (custom lambda, GPU) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Apply a custom filter using a lambda function to check if a string value, like the GPU vendor, contains a specific substring. Note that string values are lowercased before being passed to the lambda. ```python # Note: Strings are lowercased before they're passed. >>> fpgen.generate(gpu={'vendor': lambda vdr: 'nvidia' in vdr}) ``` -------------------------------- ### Filter fpgen generation (custom lambda, nested) Source: https://github.com/scrapfly/fingerprint-generator/blob/main/README.md Apply a custom filter using a lambda function for a specific nested data field. The lambda function receives the field's value and should return True if the value is acceptable. ```python # Constrain client: >>> fpgen.generate(client={'browser': {'major': lambda ver: int(ver) >= 130}}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.