Created
October 21, 2022 11:31
-
-
Save project237/f378be5a9a9f7c418a3896427f5e0c9b to your computer and use it in GitHub Desktop.
Change the requests module user agent to a specified user agent string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests as req | |
NEW_AGENT = "USER_AGENT_HERE" | |
def change_user_agent(new_agent): | |
req.utils.default_user_agent = lambda: new_agent | |
def get_user_agent(): | |
url = 'https://httpbin.org/user-agent' | |
response = req.get(url) | |
return response.request.headers | |
if __name__ == '__main__': | |
# change_user_agent(NEW_AGENT) | |
print(get_user_agent()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment