本文整理汇总了Python中urllib2.Request.headers['Range']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers['Range']方法的具体用法?Python Request.headers['Range']怎么用?Python Request.headers['Range']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.headers['Range']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrapper
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import headers['Range'] [as 别名]
def scrapper(self, resource):
"""
:param resource:
:return:
"""
try:
test_req = urlopen(resource).read()
except HTTPError as e:
print '\tThe server couldn\'t fulfill the request.'
print '\tError code: ', e.code
except URLError as e:
print '\tWe failed to reach a server.'
print '\tReason: ', e.reason
else:
tree = html.fromstring(test_req)
for link in tree.xpath('//a/@href'):
self.depth += 1
if self.depth < self.given_depth:
print "\tGoing deeper: ", link
self.scrapper(link)
print "\tWent back from some href."
for tag in self.tags:
links = tree.xpath('//%s[@%s="%s"]/text()' %
(tag[0], tag[1], tag[2]))
for link in links:
req = Request(link)
req.headers['Range'] = 'bytes=%s-%s' % (0, 30000)
f = urlopen(req)
v = f.read()
nf = open("temp.mp3", "w")
nf.write(v)
nf.close()
audio = EasyID3("temp.mp3")
artist = audio["artist"]
unicodedata.normalize('NFKD', artist[0]).\
encode('ascii', 'ignore')
title = audio["title"]
unicodedata.normalize('NFKD', title[0]).\
encode('ascii', 'ignore')
genre = audio["genre"]
unicodedata.normalize('NFKD', genre[0]).\
encode('ascii', 'ignore')
print '\tSong found: ' + artist[0] + ' - ' +\
title[0] + '; genre - ' + genre[0]
os.system("rm temp.mp3")
new_playlist_entry = []
if self.genre == genre[0]:
new_playlist_entry.append(artist[0])
new_playlist_entry.append(title[0])
new_playlist_entry.append(genre[0])
self.output_list.append(new_playlist_entry)