Here are the examples of the python api urllib2.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : service.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('User-Agent','User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
#req.add_header('Host', 'www.airspacemag.com')
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0')
#req.add_header('Referer', 'http://www.airspacemag.com/videos/')
#req.add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('Host','www.internet-radio.com')
req.add_header('User-Agent','User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError as (e):
print (e)
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('User-Agent','User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def msg_pages(url):
page = int(url.split('=')[-1])
next_page = (url.split('='))[0] + '=' + str(page +1)
req = urllib2.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B410 Safari/600.1.4')
response = urllib2.urlopen(req, timeout=60)
html = response.read()
response.close()
soup = BeautifulSoup(html,'html.parser').find_all('article',{'clast':'video-post'})
for item in soup:
satle = item.find('h2').text.encode('utf-8').strip()
url = item.find('a',{'clast':'satle_link'})['href'] + 'embed/?'
image = str(re.compile("url\\(\\'(.+?)\\'\\)").findall(str(item)))[2:-2]
add_directory3(satle, url, 85, image, image, plot='')
addDir('Next Page', next_page, 86, image)
xbmcplugin.endOfDirectory(addon_handle, cacheToDisc=True)
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
#req.add_header('Host','api.newsmaxtv.com')
#req.add_header('Accept','application/json, text/javascript, */*; q=0.01')
req.add_header('User-Agent','User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')
#req.add_header('Referer','https://www.newsmaxtv.com/')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0')
try:
response = urllib2.urlopen(req)
response.getcode()
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:48.0) Gecko/20100101 Firefox/48.0')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html
3
View Complete Implementation : addon.py
Copyright GNU General Public License v2.0
Author : MetalChris
Copyright GNU General Public License v2.0
Author : MetalChris
def get_html(url):
req = urllib2.Request(url)
req.add_header('User-Agent','User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')
try:
response = urllib2.urlopen(req)
html = response.read()
response.close()
except urllib2.HTTPError:
response = False
html = False
return html