I used fake UserAgent.
Install:
pip install fake-useragent
How to use:
from fake_useragent import UserAgent
import requests
ua = UserAgent()
print(ua.chrome)
header = {'User-Agent':str(ua.chrome)}
print(header)
url = "https://www.hybrid-analysis.com/recent-submissions?filter=file&sort=^timestamp"
htmlContent = requests.get(url, headers=header)
print(htmlContent)
Output:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17
{'User-Agent': 'Mozilla/5.0 (X11; OpenBSD i386) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36'}
<Response [200]>
Additional features are available as well. Random return a only Edge or Chrome browser user agents:
from fake_useragent import UserAgent
ua = UserAgent(browsers=['edge', 'chrome'])
ua.random
Randomly return only Linux OS user agent strings:
from fake_useragent import UserAgent
ua = UserAgent(os='linux')
ua.random
Or randomly return user agent strings with a minimum usage percentage of 1.3% or higher:
from fake_useragent import UserAgent
ua = UserAgent(min_percentage=1.3)
ua.random