爬虫,爬取猫眼电影Top100的电影名与评分
2019-08-22 18:02
134 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43790072/article/details/100020820
**
爬虫,爬取猫眼电影Top100的电影名与评分
**
import requests import threading import re class maoyan_top500(threading.Thread): def __init__(self, start_, end_,lock): threading.Thread.__init__(self) self.headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' } self.base_url = 'https://maoyan.com/board/4?offset=%d' self.start_ = start_ self.end_ = end_ self.lock = lock def run(self): for offset in range(self.start_, self.end_, 10): url = self.base_url % offset response = requests.get(url, headers=self.headers) html = response.text info_list = self.get_Information(html) with self.lock: self.write(info_list) print('offset {} OK !'.format(offset)) def get_Information(self, html): information_list = [] for line in html.split('\n'): if 'class="image-link"' in line: movie_name = line.split('title="')[1].split('"')[0] information_list.append(movie_name) if 'class="integer"' in line: res = re.search( '<p class="score"><i class="integer">(\d\.)</i><i class="fraction">(\d)</i></p>', line) integer = res.group(1) fraction = res.group(2) score = integer + fraction information_list.append(score) return information_list def write(self,info_list): str_ = str(info_list) + '\n' with open('D:\\mixhhh\\邮箱\\电影\\top5000.txt',mode='a',encoding='utf8') as file: file.write(str_) if __name__ == "__main__": threads = [] lock = threading.Lock() for i in range(2): t = maoyan_top500(start_=i * 50, end_=(i + 1) * 50,lock=lock) t.start() threads.append(t) for t in threads: t.join() print('Over')
输出:
相关文章推荐
- 【python爬虫】猫眼电影TOP100电影封面下载
- Python爬虫(三):爬取猫眼电影网经典电影TOP100信息并存入本地Markdown文件(上)
- Python爬虫(三):爬取猫眼电影网经典电影TOP100信息并存入本地Markdown文件(下)
- 爬取猫眼电影网经典电影TOP100信息Markdown效果展示
- python爬虫之豆瓣电影评分
- 编写Python爬虫抓取豆瓣电影TOP100及用户头像的方法
- 一个简单的爬虫,爬取豆瓣上某部电影的所有评论及计算评分
- python爬虫入门练习:BeautifulSoup爬取猫眼电影TOP100排行榜,pandas保存本地excel文件
- 喝最烈的酒,熬最深的夜之高评分电影爬虫
- python爬虫入门练习:正则表达式爬取猫眼电影TOP100排行榜,openpyxl保存本地excel文件
- python爬虫小例子:爬取猫眼电影Top10电影相关信息(代码超详细解读)
- 编写Python爬虫抓取豆瓣电影TOP100及用户头像的方法
- Python学习笔记 第二部分 - 正则表达式 与 爬虫小实例(抓取豆瓣电影中评分大于等于8分的影片)
- 利用BeatifulSoup包学习爬虫,抓取《今晚看啥》电影评分和标签
- Python爬虫之requests+正则表达式抓取猫眼电影top100以及瓜子二手网二手车信息(四)
- python读取json文件根据电影ip求电影名的评分总和并按评分排序
- 一起学爬虫——使用xpath库爬取猫眼电影国内票房榜
- python爬虫:爬取猫眼电影(分数的处理和多线程)
- 从豆瓣电影评分算法说起
- 用python+selenium抓取豆瓣电影中的正在热映前12部电影并按评分排序