Search Movie Resources Assistant

My girlfriend said that she often couldn't find movie resources to watch, and she was planning to leave her job recently, so she became a small assistant.

Version 1: Only the function of searching for movie magnet links, and gradually increase the function

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 30 17:01:26 2018

@author: gzs10227

Search for movie resources
"""

import re,os
import requests
import time,datetime
import urllib
import sys
stderr = sys.stderr
stdout = sys.stdout
reload(sys)
sys.setdefaultencoding('utf8')
sys.stderr = stderr
sys.stdout = stdout
urllib.getproxies_registry = lambda: {}
null = ''
from lxml import etree
local import

HEADERS = {
    'X-Requested-With': 'XMLHttpRequest',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '
                  '(KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
}

print u'Please enter the movie you want to search for:'
keyword = raw_input().decode(sys.stdin.encoding or locale.getpreferredencoding(True))

print u'\nPlease enter the path where you want to save the file: such as E:\movie search'
save_path = raw_input().decode(sys.stdin.encoding or locale.getpreferredencoding(True))
save = os.path.join(save_path+'\\',keyword+'.txt')
fle = open(save,'w')


def open_url(url):
    html = requests.get(url,headers = HEADERS).content
    web_data = etree.HTML(html)
    return web_data


def get_url(keyword):
    main_url = 'http://www.btyunsou.me/search/%s_ctime_1.html'%keyword
    web_data = open_url(main_url)
    links = web_data.xpath('//li[@class="media"]//h4//a/@href') # Get links
    links = ['http://www.btyunsou.me'+i for i in links]
    return links


def get_info(url):    
    web_data = open_url(url)
    try:
        title = web_data.xpath(r'//div[@class="row-flbtd tor-title"]/h2/text()')[0]
    except:
        title = ''
    if keyword in title:        
        print u'movie name:',title
        mange_link = 'magnet:? xt = urn: btih:' + url [23: -5]
        print u'Magnetic link: ',mange_link
        fle.write(u'movie name:'+ title + '\n')
        fle.write(u'magnet link: ' + mange_link +'\n')
        datalist = web_data.xpath(r'//table[@class="table detail table-hover"]/tbody//tr//td/text()')[:10]
        for i in range(0,len(datalist),2):
            print datalist[i],datalist[i+1]
            fle.write(datalist[i] + datalist[i+1] + '\n')
    else:
        print 'Sorry! None Search,Please change one: '


if __name__ == '__main__':       
    i = 1
    while True:    
        if i > 1:
            print u'Please enter the movie you want to search for:'
            keyword = raw_input().decode(sys.stdin.encoding or locale.getpreferredencoding(True))
            save = os.path.join(save_path,keyword+'.txt')
            fle = open(save,'w')
        links = get_url(keyword)
        for url in links:            
            get_info(url)
            fle.write('--------------------------------------------------')
            fle.write('\n')
        fle.close()
        i = i + 1
        print u'\nIf you want to search again, enter the movie name! Otherwise please close the window manually.\n'
    
 
 
Configuration file:
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 30 19:27:06 2018


@author: gzs10227
"""


from distutils.core import setup  
import py2exe  
import sys
sys.setrecursionlimit (5000)
setup(console=["search_movie.py"],
	    options={
        'py2exe': 
        {
            'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'],
        }
    }
    
You need to install py2exe, and then enter python mysetup.py py2exe in cmd.
    
    


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325704244&siteId=291194637