# coding=utf-8
import os, sys
# 配置第三方python包的路径
lib_path = os.path.join(sys.path[0], 'resources', 'lib')
# print lib_path
sys.path.append(lib_path)
# print sys.path
import urllib2
import gzip
import StringIO
import re
import time, random
import json
from xbmcswift2 import Plugin
from bs4 import BeautifulSoup
from bs4 import SoupStrainer
plugin = Plugin()
# 伪装成浏览器访问
UserAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'
# UserAgent = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'
# 亲宝儿歌url地址
# url = 'http://www.youku.com/show_page/id_z750491c6a69911e2b2ac.html'
# 解析url,返回html_doc文档
def Get_Html_Doc(url):
req = urllib2.Request(url)
req.add_header('User-Agent', UserAgent)
response = urllib2.urlopen(req)
html_doc = response.read()
if response.headers.get('content-encoding', None) == 'gzip':
html_doc = gzip.GzipFile(fileobj=StringIO.StringIO(html_doc)).read()
charset = response.headers.getparam('charset')
response.close()
match = re.compile('
if match:
charset = match[0]
else:
match = re.compile('
if match:
charset = match[0]
if charset:
charset = cha