Changing user agent on urllib2.urlopen

I answered a similar question a couple weeks ago. There is example code in that question, but basically you can do something like this: (Note the capitalization of User-Agent as of RFC 2616, section 14.43.) opener = urllib2.build_opener() opener.addheaders = [(‘User-Agent’, ‘Mozilla/5.0’)] response = opener.open(‘http://www.stackoverflow.com’)

Way to change Google Chrome user agent in Selenium?

A simple way to use a random User Agent would be using Python’s fake_useragent module as follows : from selenium import webdriver from selenium.webdriver.chrome.options import Options from fake_useragent import UserAgent options = Options() ua = UserAgent() userAgent = ua.random print(userAgent) options.add_argument(f’user-agent={userAgent}’) driver = webdriver.Chrome(chrome_options=options, executable_path=r’C:\WebDrivers\ChromeDriver\chromedriver_win32\chromedriver.exe’) driver.get(“https://www.google.co.in”) driver.quit() Result of 3 consecutive execution is as follows … Read more

Setting user agent of a java URLConnection

Just for clarification: setRequestProperty(“User-Agent”, “Mozilla …”) now works just fine and doesn’t append java/xx at the end! At least with Java 1.6.30 and newer. I listened on my machine with netcat(a port listener): $ nc -l -p 8080 It simply listens on the port, so you see anything which gets requested, like raw http-headers. And … Read more

Get operating system info

The code below could explain in its own right, how http://thismachine.info/ is able to show which operating system someone is using. What it does is that, it sniffs your core operating system model, for example windows nt 5.1 as my own. It then passes windows nt 5.1/i to Windows XP as the operating system. Using: … Read more