+
+
Posts List
  1. 程序描述
  2. 涉及知识点
  3. 代码

Python编程快速上手(六)人人影视资源搜索器

程序描述

输入关键字,在人人影视中搜索影视剧,回显搜索结果,输入编号得到ed2k链接🔗。

由于人人影视采用等级制度,资源下载链接需要登录后才能查看,所以这里用session模拟登陆。这一块参考了Github上tengbozhang/renren这一项目。

涉及知识点

  • session
  • requests
  • bs4
  • RegEx

代码

#! python3
# -*- coding: utf-8 -*-

import webbrowser, requests, sys, bs4, re

headers = {
'Accept':'application/json, text/javascript, */*; q=0.01',
'Origin':'http://www.zimuzu.tv',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
}

if len(sys.argv) < 2:
keywords = input()
url = 'http://www.zimuzu.io/search?keyword='+ keywords +'&type=resource'
else:
url = 'http://www.zimuzu.io/search?keyword='+' '.join(sys.argv[1:])+'&type=resource'

res = requests.get((url),headers = headers)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text,"html.parser")

#print search result and make a choice
linkElems = soup.select('.t a')
for piece in linkElems:
snum = str(piece.get('href'))[10:]
print('['+ snum +']', end='')
rr = re.compile(r'"list_title">(.*?)<\/strong>')
print(rr.findall(str(piece))[0])
cho = input()

#print download urls
dlUrl = 'http://www.zimuzu.io/resource/list/' + cho
username = ''
password = ''
loginurl = 'http://www.zimuzu.io/User/Login/ajaxLogin'
data = "account=" + username + "&password="+ password + "&remember=1"
session = requests.Session()
login = session.post(loginurl,data = data,headers = headers)
dlSoup = bs4.BeautifulSoup(session.get(dlUrl).content.decode('utf-8'),"html.parser")
dlElems = dlSoup.find_all('a', {"type" : "ed2k"})
for piece in dlElems:
print(piece.get('href'))

本文作者: rhinoc

本文链接: http://rhinoc.top/post/python_6.html

版权声明: 本博客所有文章除特别声明外,均采用BY-NC-SA 4.0国际许可协议,转载请注明。

Support
Support Me
  • Through WeChat
  • Through Alipay