#16进制 base64
import base64
import requests
from pyquery import PyQuery as pq
class Decode:
def getHex(self,param1):
return {
'str': param1[4:],#截取前面四个数字字母之后
'hex': ''.join(list(param1[:4])[::-1]),#四个数字字母截取后数字倒序输出
}
def getDecimal(self, param1):
loc2 = str(int(param1, 16))#四个数字字母转换16进制数
print(loc2)#
return {
'pre': list(loc2[:2]),#四个 数字分为两个
'tail': list(loc2[2:]),
}
def substr(self, param1, param2):
loc3 = param1[0: int(param2[0])]
print(loc3)
loc4 = param1[int(param2[0]): int(param2[0]) + int(param2[1])]
print("loc4",loc4)
return loc3 + param1[int(param2[0]):].replace(loc4, "")
def getPosition(self,param1, param2):
param2[0] = len(param1) - int(param2[0]) - int(param2[1])
return param2
def decode(self, code):
dict2 = self.getHex(code)
dict3 = self.getDecimal(dict2['hex'])
print("dict3", dict3['pre']) #提取 四个数字前两个数字
str4 = self.substr(dict2['str'], dict3['pre'])#提取 截取四个之后 其余部分
return base64.b64decode(self.substr(str4, self.getPosition(str4, dict3['tail'])))
def crawl_video_url(self, url):
response = requests.get(url).content
d = pq(response)##初始化为PyQuery对象
code= d('meta[property="og:video:url"]').attr('content')
result = self.decode(code)
print(result)
if __name__ == '__main__':
url = "http://www.meipai.com/media/816057957"
Decode().crawl_video_url(url)
mp
最新推荐文章于 2022-11-04 11:00:38 发布