当前位置: 首页>>代码示例>>Python>>正文


Python urllib2.urlopen2函数代码示例

本文整理汇总了Python中urllib2.urlopen2函数的典型用法代码示例。如果您正苦于以下问题:Python urlopen2函数的具体用法?Python urlopen2怎么用?Python urlopen2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了urlopen2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search_poster

def search_poster(id):
    url = 'http://www.kinopoisk.ru/level/17/film/%s' % id
    watchrequest = Request(url, None, std_headers)
    try:
        watchvideopage = urlopen2(watchrequest)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    data = watchvideopage.read().decode('cp1251').encode('utf-8')
    coveritems = []
    watchvideopage.close()
    if '<table class="fotos' in data:
        coveritems = multiValue(data, '<table class="fotos.*?">(.*?)</table>', '<a href="(.*?)">')
        Coverart = coveritems[0]
        url2 = 'http://www.kinopoisk.ru%s' % Coverart
        watchrequest2 = Request(url2, None, std_headers)
        try:
            watchvideopage2 = urlopen2(watchrequest2)
        except (URLError, HTTPException, socket.error) as err:
            print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

        data2 = watchvideopage2.read().decode('cp1251').encode('utf-8')
        coveritem = ''
        coveritem = singleValue(data2, '<img style=".*?" id="image" src="(.*?)".*?/>')
        watchvideopage2.close()
    else:
        coveritem = 'None'
    return coveritem
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:28,代码来源:kinopoiskall.py

示例2: poster_viemtmbd

def poster_viemtmbd(id):
    url = 'http://www.themoviedb.org%s' % id
    watchrequest = Request(url, None, std_headers)
    try:
        watchvideopage = urlopen2(watchrequest)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    data = watchvideopage.read()
    search_results = []
    watchvideopage.close()
    if '<div id="images">' in data:
        content_results = singleValue(data, '<div id="images">(.*?)</div>')
        if content_results:
            idposters = re.compile('<img itemprop=".*?" class=".*?" id=".*?" src="(.*?)" width=".*?" height=".*?" />').findall(content_results)
            imagessaizes = re.compile('<img itemprop=".*?" class=".*?" id="(.*?)" src=".*?" width=".*?" height=".*?" />').findall(content_results)
            for imagessaize in imagessaizes:
                search_results.append('image:' + imagessaize)

            l = 0
            for idposter in idposters:
                if l < len(idposters):
                    search_results[l] = search_results[l] + '\n link:' + idposter + 'end'
                l += 1

    return search_results
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:26,代码来源:kinopoiskall.py

示例3: poster_viem

def poster_viem(id):
    url = 'http://www.kinopoisk.ru/level/17/film/%s' % id
    watchrequest = Request(url, None, std_headers)
    try:
        watchvideopage = urlopen2(watchrequest)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    data = watchvideopage.read().decode('cp1251').encode('utf-8')
    search_results = []
    watchvideopage.close()
    if '<table class="fotos' in data:
        content_results = singleValue(data, '<table class="fotos.*?">(.*?)</table>')
        if content_results:
            results = CrewRoleList3(content_results)
            idposters = re.compile('<a href="(.*?)" target="_blank" title="\xd0\x9e\xd1\x82\xd0\xba\xd1\x80\xd1\x8b\xd1\x82\xd1\x8c \xd0\xb2 \xd0\xbd\xd0\xbe\xd0\xb2\xd0\xbe\xd0\xbc \xd0\xbe\xd0\xba\xd0\xbd\xd0\xb5"></a>').findall(content_results)
            imageslinks = re.compile('<img  src="(.*?)".*?/></a>').findall(content_results)
            imagessaizes = re.compile('<span class="genre">(.*?)</span>').findall(results)
            for imagessaize in imagessaizes:
                search_results.append('size:' + imagessaize)

            i = 0
            for idposter in idposters:
                if i < len(idposters):
                    search_results[i] = search_results[i] + '\n\n (' + idposter + ')'
                i += 1

            l = 0
            for imageslink in imageslinks:
                if l < len(imageslinks):
                    search_results[l] = search_results[l] + '\n link:' + imageslink + 'end'
                l += 1

    return search_results
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:34,代码来源:kinopoiskall.py

示例4: getMovieUrl

def getMovieUrl(url):
	req = Request(url, None, std_headers)
	try:
		txt = urlopen2(req).read()
	except (URLError, HTTPException, error), err:
		print "[ZDFMediaThek] Error: Unable to retrieve videopage - Error code: ", str(err)
		return ""
开发者ID:Haehnchen,项目名称:enigma2-plugins,代码行数:7,代码来源:plugin.py

示例5: getVideoUrl

	def getVideoUrl(self):
		'''VIDEO_FMT_PRIORITY_MAP = {
			'38' : 1, #MP4 Original (HD)
			'37' : 2, #MP4 1080p (HD)
			'22' : 3, #MP4 720p (HD)
			'18' : 4, #MP4 360p
			'35' : 5, #FLV 480p
			'34' : 6, #FLV 360p
		}'''
		VIDEO_FMT_PRIORITY_MAP = {
			'34' : 2, #FLV 360p
			'35' : 1, #FLV 480p
			'18' : 3, #MP4 360p
			'22' : 4, #MP4 720p (HD)
			'37' : 5, #MP4 1080p (HD)
			'38' : 6, #MP4 Original (HD)  
		}
		
		video_url = None
		video_id = str(self.getTubeId())

		links = {}
		watch_url = 'http://www.youtube.com/watch?v=%s&safeSearch=none'%video_id
		watchrequest = Request(watch_url, None, std_headers)

		try:
			print "[MyTube] trying to find out if a HD Stream is available",watch_url
			result = urlopen2(watchrequest).read()
		except (URLError, HTTPException, socket.error), err:
			print "[MyTube] Error: Unable to retrieve watchpage - Error code: ", str(err)
			return video_url
开发者ID:popazerty,项目名称:e2-gui,代码行数:31,代码来源:MyTubeService.py

示例6: getVideoUrl

    def getVideoUrl(self, entry):
        std_headers = {
            "User-Agent": "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.6) Gecko/20100627 Firefox/3.6.6",
            "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Accept-Language": "en-us,en;q=0.5",
        }

        VIDEO_FMT_PRIORITY_MAP = {"18": 4, "35": 5, "34": 6}  # MP4 360p  # FLV 480p  # FLV 360p

        if int(config.plugins.yttrailer.best_resolution.value) <= 1:
            VIDEO_FMT_PRIORITY_MAP["38"] = 1  # MP4 Original (HD)
            VIDEO_FMT_PRIORITY_MAP["22"] = 3  # MP4 720p (HD)

            if int(config.plugins.yttrailer.best_resolution.value) == 0:
                VIDEO_FMT_PRIORITY_MAP["37"] = 2  # MP4 1080p (HD)

        video_url = None
        video_id = str(self.getTubeId(entry))

        # Getting video webpage
        # URLs for YouTube video pages will change from the format http://www.youtube.com/watch?v=ylLzyHk54Z0 to http://www.youtube.com/watch#!v=ylLzyHk54Z0.
        watch_url = "http://www.youtube.com/watch?v=%s&gl=US&hl=en" % video_id
        watchrequest = Request(watch_url, None, std_headers)
        try:
            print "[YTTrailer] trying to find out if a HD Stream is available", watch_url
            watchvideopage = urlopen2(watchrequest).read()
        except (URLError, HTTPException, socket_error), err:
            print "[YTTrailer] Error: Unable to retrieve watchpage - Error code: ", str(err)
            return video_url
开发者ID:hd75hd,项目名称:enigma2-plugins,代码行数:30,代码来源:plugin.py

示例7: wgetUrlRefer

def wgetUrlRefer(target, refer):
	req = Request(target)
	req.add_header('Referer', refer)
	try:
		r = urlopen2(req)
		outtxt = r.read()
	except:
		outtxt = ''
	return outtxt
开发者ID:Firestorm552,项目名称:oe-alliance-plugins,代码行数:9,代码来源:plugin.py

示例8: poster_save

def poster_save(id):
    url2 = 'http://www.kinopoisk.ru%s' % id
    watchrequest2 = Request(url2, None, std_headers)
    try:
        watchvideopage2 = urlopen2(watchrequest2)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    data2 = watchvideopage2.read().decode('cp1251').encode('utf-8')
    coveritem = ''
    coveritem = singleValue(data2, '<img style=".*?" id="image" src="(.*?)".*?/>')
    watchvideopage2.close()
    return coveritem
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:13,代码来源:kinopoiskall.py

示例9: wgetUrl

def wgetUrl(target):
	std_headers = {
		'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.6) Gecko/20100627 Firefox/3.6.6',
		'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
		'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
		'Accept-Language': 'en-us,en;q=0.5',
	}
	outtxt = Request(target, None, std_headers)
	try:
		outtxt = urlopen2(target, timeout = 5).read()
	except (URLError, HTTPException, socket.error):
		return ''
	return outtxt
开发者ID:Firestorm552,项目名称:oe-alliance-plugins,代码行数:13,代码来源:plugin.py

示例10: getVideoUrl

	def getVideoUrl(self, video_id):
		video_url = None

		if video_id is None or video_id == "":
			return video_url

		# Getting video webpage
		watch_url = 'http://www.youtube.com/watch?v=%s&gl=US&hl=en' % video_id
		watchrequest = Request(watch_url, None, std_headers)
		try:
			#print "trying to find out if a HD Stream is available",watch_url
			watchvideopage = urlopen2(watchrequest).read()
		except (URLError, HTTPException, socket.error), err:
			print "Error: Unable to retrieve watchpage - Error code: ", str(err)
			return video_url
开发者ID:R7UST,项目名称:oe-alliance-plugins,代码行数:15,代码来源:plugin.py

示例11: postto

def postto(url, datadict, headers={}, decodec='gbk'):
    params = urlencode(datadict)
    _logger.info('Post %s to %s, headers %s', params, url, headers)
    try:
        req = Request(url=url, data=params)
        for k,v in headers.items():
            req.add_header(k,v)
        con = urlopen2(req)
        if con:
            _logger.info("Hit %s %d", str(con), con.getcode())
            data = con.read(-1)
            return data.decode(decodec)
        else: 
            _logger.error("No data returned.")
            return None

    except Exception, err:
        _logger.error(str(err))
开发者ID:genzj,项目名称:list370kan-appfog,代码行数:18,代码来源:util.py

示例12: youtube

	def youtube(self, url, videoPrio=2):
		# this part is from mtube plugin
		print "got url: " + str(url)
		if videoPrio == 0:
			VIDEO_FMT_PRIORITY_MAP = {
				'38' : 6, #MP4 Original (HD)
				'37' : 5, #MP4 1080p (HD)
				'22' : 4, #MP4 720p (HD)
				'35' : 2, #FLV 480p
				'18' : 1, #MP4 360p
				'34' : 3, #FLV 360p
			}
		elif videoPrio == 1:
			VIDEO_FMT_PRIORITY_MAP = {
				'38' : 6, #MP4 Original (HD)
				'37' : 5, #MP4 1080p (HD)
				'22' : 1, #MP4 720p (HD)
				'35' : 3, #FLV 480p
				'18' : 2, #MP4 360p
				'34' : 4, #FLV 360p
			}
		else:
			VIDEO_FMT_PRIORITY_MAP = {
				'38' : 3, #MP4 Original (HD)
				'37' : 1, #MP4 1080p (HD)
				'22' : 2, #MP4 720p (HD)
				'35' : 5, #FLV 480p
				'18' : 4, #MP4 360p
				'34' : 6, #FLV 360p
			}
		video_url = None
		url = url.replace('/embed/', '/watch?v=')
		id = re.findall('watch.v=(.*\D)', url, re.S)
		video_id = id[0]
		# Getting video webpage
		#URLs for YouTube video pages will change from the format http://www.youtube.com/watch?v=ylLzyHk54Z0 to http://www.youtube.com/watch#!v=ylLzyHk54Z0.
		watch_url = 'http://www.youtube.com/watch?v=%s&gl=DE&hl=de' % video_id
		watchrequest = Request(watch_url, None, std_headers)
		try:
			print "[youtubeUrl] trying to find out if a HD Stream is available",watch_url
			watchvideopage = urlopen2(watchrequest).read()
		except (URLError, HTTPException, socket.error), err:
			return "Error: Unable to retrieve watchpage - Error code: %s" % str(err)
开发者ID:lilmuck,项目名称:lilmuck,代码行数:43,代码来源:stream.py

示例13: search_comets

def search_comets(id):
    url = 'http://www.kinopoisk.ru/level/1/film/' + id
    watchrequest = Request(url, None, std_headers)
    try:
        watchvideopage = urlopen2(watchrequest)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    content = watchvideopage.read().decode('cp1251').encode('utf-8')
    watchvideopage.close()
    search_results = []
    content_results = content[content.find('<p class="more_random">'):content.find('\xd0\x94\xd0\xbb\xd1\x8f \xd1\x82\xd0\xbe\xd0\xb3\xd0\xbe \xd1\x87\xd1\x82\xd0\xbe\xd0\xb1\xd1\x8b \xd0\xb4\xd0\xbe\xd0\xb1\xd0\xb0\xd0\xb2\xd0\xb8\xd1\x82\xd1\x8c \xd1\x80\xd0\xb5\xd1\x86\xd0\xb5\xd0\xbd\xd0\xb7\xd0\xb8\xd1\x8e \xd0\xbd\xd0\xb0 \xd1\x84\xd0\xb8\xd0\xbb\xd1\x8c\xd0\xbc, \xd0\xbd\xd0\xb5\xd0\xbe\xd0\xb1\xd1\x85\xd0\xbe\xd0\xb4\xd0\xb8\xd0\xbc\xd0\xbe')]
    if content_results:
        results = CrewRoleList2(content_results)
        names = normilize_string(singleValue(results, '<p class="profile_name"><s></s><a href=".*?" itemprop="name">(.*?)</a></p>'))
        titleitems = normilize_string(singleValue(results, '<span class="_reachbanner_" itemprop="reviewBody">(.*?)</span></p> </div>'))
        iditems = normilize_string(singleValue(results, '<p class="sub_title" id=".*?">(.*?)</p>'))
        search = '%s\n\n%s\n\n%s' % (names, iditems, titleitems)
        search_results.append(search)
    return search_results
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:20,代码来源:kinopoiskall.py

示例14: search_tmbd

def search_tmbd(title):
    url = 'http://www.themoviedb.org/search?query=%s' % title
    watchrequest = Request(url, None, std_headers)
    try:
        watchvideopage = urlopen2(watchrequest)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    data = watchvideopage.read()
    search_results = []
    watchvideopage.close()
    if '<div class="search_results movie ">' in data:
        content_results = singleValue(data, '<div class="search_results movie ">(.*?)<div class="search_results collection hide">')
        if content_results:
            iditems = re.compile('<a id=".*?" class="result" href="(.*?)" title=".*?" alt=".*?">').findall(content_results)
            years = re.compile('<span class="release_date"> (.*?) <span class=".*?"></span></span>').findall(content_results)
            directors = re.compile('<span class="genres">(.*?)</span>').findall(content_results)
            images = re.compile('<img class="poster lazyload" data-src="(.*?)" .*? alt=".*?">').findall(content_results)
            titleitems = re.compile('<a id=".*?" class="result" href=".*?" title="(.*?)" alt=".*?">').findall(content_results)
            for titleitem in titleitems:
                search_results.append(titleitem)

            d = 0
            for director in directors:
                if d < len(directors):
                    search_results[d] = search_results[d] + '\n year: ' + years[d] + '\n \xd1\x80\xd0\xb5\xd0\xb6. ' + director
                d += 1

            l = 0
            for iditem in iditems:
                if l < len(iditems):
                    search_results[l] = search_results[l] + '\n' + 'id:' + iditem + 'end'
                l += 1

            e = 0
            for image in images:
                if e < len(images):
                    search_results[e] = search_results[e] + '\n' + 'image:' + image + 'ends'
                e += 1

    return search_results
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:41,代码来源:kinopoiskall.py

示例15: search_postermp3

def search_postermp3(url):
    watchrequest = Request(url, None, std_headers)
    try:
        watchvideopage = urlopen2(watchrequest)
    except (URLError, HTTPException, socket.error) as err:
        print '[Kinopoisk] Error: Unable to retrieve page - Error code: ', str(err)

    data = watchvideopage.read()
    search_results = []
    cover = ''
    watchvideopage.close()
    if 'src="' in data:
        coveritems = re.compile('src="(.*?)"').findall(data)
        for coveritem in coveritems:
            if 'http://' in coveritem:
                if '&imgurl=' in coveritem:
                    search_results.append(singleValue(coveritem, '&imgurl=(.*?)&w='))
                else:
                    search_results.append(coveritem)

    return search_results
开发者ID:Dima73,项目名称:enigma2-plugin-extensions-tmbd,代码行数:21,代码来源:kinopoiskall.py


注:本文中的urllib2.urlopen2函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。