fake_requests_headers

pyhelpers.ops.fake_requests_headers(randomized=True, **kwargs)

Make a fake HTTP headers for requests.get.

Parameters
  • randomized (bool) – whether to use a user-agent string randomly selected from among all available data of several popular browsers, defaults to True; if randomized=False, the function uses a random Chrome user-agent string

  • kwargs – [optional] parameters of the function pyhelpers.ops.get_user_agent_string()

Returns

fake HTTP headers

Return type

dict

Examples:

>>> from pyhelpers.ops import fake_requests_headers

>>> fake_headers_1 = fake_requests_headers()
>>> fake_headers_1
{'user-agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT) AppleWebKit/525.19 (KHTML...

>>> fake_headers_2 = fake_requests_headers(randomized=False)
>>> fake_headers_2  # using a random Chrome user-agent string
{'user-agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.1 (KHTML,...

Note

  • fake_headers_1 may also be different every time we run the example. This is because the returned result is randomly chosen from a limited set of candidate user-agent strings, even though randomized is (by default) set to be False.

  • By setting randomized=True, the function returns a random result from among all available user-agent strings of several popular browsers.