0

Quiz

question:how to open a website? like: input:www.yahoo.com output:a website page”www.yahoo.com” Any language except JavaScript,HTML,CSS is welcome.

11th May 2018, 6:45 AM
You
You - avatar
4 odpowiedzi
+ 3
This can be done in Python using the "webbrowser" module: " # Tutorial: https://www.idiotinside.com/2015/03/07/open-an-url-on-web-browser-programmatically-in-python # Documentation: https://docs.python.org/3/library/webbrowser.html # Tested on Python 2.7.6 import webbrowser url = 'http://idiotinside.com' # Open URL in new browser window webbrowser.open_new(url) # opens in default browser # Opens in safari browser webbrowser.get('safari').open_new(url) # Open URL in a new tab webbrowser.open_new_tab(url) # opens in default browser # Opens in safari browser webbrowser.get('safari').open_new_tab(url) " Source: https://www.idiotinside.com/2015/03/07/open-an-url-on-web-browser-programmatically-in-python/ " How to open a webpage using java code" http://www.instanceofjava.com/2016/08/how-to-open-webpage-using-java-code.html?m=1
11th May 2018, 6:54 AM
Rahul George
Rahul George - avatar
+ 1
in python using urlib and regex import regex as re import urllib.parse import urllib.request try: url = 'https://google.com/search?q=test' headers = {} headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0' url = 'https://pythonprogramming.net' value = {'s':'basic', 'submit' :'search'} data=urllib.parse.urlencode(value) data = data.encode('utf-8') req = urllib.request.Request(url,data,headers=headers ) resp= urllib.request.urlopen(req) respData=resp.read() print(respData) save = re.findall(r'<p>(.*?)</p>',str(respData)) for i in save: print(i) save = open('headergog.txt','w') save.write(str(respData)) save.close() except Exception as e: print(str(e))
11th May 2018, 6:50 AM
‎ ‏‏‎Anonymous Guy
+ 1
@Sreejith Thank you! Is this right? import webbrowser webbrowser.open(‘www.yahoo.com’)
11th May 2018, 6:55 AM
You
You - avatar
+ 1
yes it's right this may help you https://docs.python.org/2/library/webbrowser.html
11th May 2018, 6:59 AM
‎ ‏‏‎Anonymous Guy