没有注意论坛有没有相关的帖子,暂吾爱资讯太多了,内容丰富,生怕有重复的,如果重复了,请管理删帖。
自学Python一段时间了,写的代码比较紊乱,也不多,大佬勿喷。
[Python] 纯文本查看 复制代码 #!/usr/bin/env python
# -*- coding: utf-8 -*-
# [url=home.php?mod=space&uid=686237]@date[/url] : 2018-07-30 17:14:11
# [url=home.php?mod=space&uid=686208]@AuThor[/url] : --Eruy-- ([url=mailto:yl8923@qq.com]yl8923@qq.com[/url])
# @Version : $Id$
#请求库
import requests
#解析库 bs4 css pyquery json xpath re
from lxml import etree
# 类
class MiNiMp4(object):
"""docstring for GetMovies"""
def GetMovies(self, page):
url = 'http://www.minimp4.com/movie/?page={}'.format(page)
html = requests.get(url)
htmll = etree.HTML(html.text) #初始化xml
hrefs = htmll.xpath('//div[@class="meta"]/h1/a/@href')
# print(hrefs)
for url in hrefs:
html = requests.get(url)
dat = etree.HTML(html.text)
movieName = dat.xpath('//div[@class="movie-meta"]/h1/text()')
print(movieName)
self.saveMovies(movieName)
# return url
#
@staticmethod
def saveMovies(data):
with open('movies.txt','a',encoding='utf-8') as fp:
fp.write(data[0]+'\n')
if __name__ == "__main__":
minimp4 = MiNiMp4()
for n in range(10):
minimp4.GetMovies(n)
|