python爬虫知识点总结(九)Requests+正则表达式爬取猫眼电影
一、爬取流程

二、代码演示
#-*- coding: UTF-8 -*-
#_author:AlexCthon
#mail:alexcthon@163.com
#date:2018/8/3 import requests
from multiprocessing import Pool # 进程池,用来实现秒抓
from requests.exceptions import RequestException
import re
import json
def get_one_page(url):
try:
response = requests.get(url)
#print(response.text)
if(response.status_code == 200):
return response.text
return None
except RequestException:
return None def parse_one_page(html):
pattern = re.compile('<dd>.*?board-index.*?>(\d+)</i>.*?data-src="(.*?)".*?name"><a.*?>(.*?)</a>.*?star">(.*?)</p>.*?releasetime">(.*?)</p>.*?integer">(.*?)</i>.*?fraction">(.*?)</i>.*?</dd>',re.S)
items = re.findall(pattern,html)
for item in items:
yield{
'index':item[0],
'image':item[1],
'title':item[2],
'actor':item[3].strip()[3:],
'time':item[4].strip()[5:],
'score':item[5]+item[6]
} def write_to_file(content):
with open('result.txt','a',encoding='utf-8')as f:
f.write(json.dumps(content,ensure_ascii=False) + '\n')
f.close() def main(offset):
url = 'http://maoyan.com/board/4?offset='+str(offset)
html = get_n=get_one_page(url)
for item in parse_one_page(html):
print(item)
write_to_file(item) if __name__ == '__main__':
pool = Pool()
pool.map(main,[i*10 for i in range(10)])
python爬虫知识点总结(九)Requests+正则表达式爬取猫眼电影的更多相关文章
- PYTHON 爬虫笔记八:利用Requests+正则表达式爬取猫眼电影top100(实战项目一)
利用Requests+正则表达式爬取猫眼电影top100 目标站点分析 流程框架 爬虫实战 使用requests库获取top100首页: import requests def get_one_pag ...
- Python爬虫学习==>第十章:使用Requests+正则表达式爬取猫眼电影
学习目的: 通过一个一个简单的爬虫应用,初窥门径. 正式步骤 Step1:流程框架 抓取单页内容:利用requests请求目标站点,得到单个页面的html代码,返回结果: 正则表达式分析:根据html ...
- Requests+正则表达式爬取猫眼电影
目标 提取出猫眼电影TOP100的电影名称.时间.评分.图片等信息,提取站点的URL为http://maoyan.com/board/4,提取的结果以文本的形式保存下来. 准备工作 请安装好reque ...
- Requests+正则表达式爬取猫眼电影(TOP100榜)
猫眼电影网址:www.maoyan.com 前言:网上一些大神已经对猫眼电影进行过爬取,所用的方法也是各有其优,最终目的是把影片排名.图片.名称.主要演员.上映时间与评分提取出来并保存到文件或者数据库 ...
- Requests+正则表达式 爬取猫眼电影
代码: import re import json from multiprocessing import Pool import requests from requests.exceptions ...
- python爬虫从入门到放弃(九)之 Requests+正则表达式爬取猫眼电影TOP100
import requests from requests.exceptions import RequestException import re import json from multipro ...
- Python爬虫实战之Requests+正则表达式爬取猫眼电影Top100
import requests from requests.exceptions import RequestException import re import json # from multip ...
- 14-Requests+正则表达式爬取猫眼电影
'''Requests+正则表达式爬取猫眼电影TOP100''''''流程框架:抓去单页内容:利用requests请求目标站点,得到单个网页HTML代码,返回结果.正则表达式分析:根据HTML代码分析 ...
- Python爬虫之requests+正则表达式抓取猫眼电影top100以及瓜子二手网二手车信息(四)
requests+正则表达式抓取猫眼电影top100 一.首先我们先分析下网页结构 可以看到第一页的URL和第二页的URL的区别在于offset的值,第一页为0,第二页为10,以此类推. 二.< ...
随机推荐
- jquery判断复选框是否被选中
$("#isUse").click(function(){ if($(this).is(':checked')){ $(this).attr('checked','checked' ...
- Asp.Net北大青鸟总结(四)-使用GridView实现真假分页
这段时间看完了asp.net视频.可是感觉到自己的学习好像没有巩固好,于是又在图书馆里借了几本关于asp.net的书感觉真的非常好自己大概对于asp.net可以实现主要的小Demo.可是我知道仅仅有真 ...
- Appium python自动化测试系列之使用HTMLTestRunner生成测试报告(十三)
13.1 测试报告概述 13.1.1 测试报告的定义 在前面章节我们已经讲了自动化基础的很多东西,如果说掌握了,而且自己动手去练习了,我相信在一些初级的面试中是没任何问题的,今天我们接触的应该算是一 ...
- ios美颜 调研 GPUImage GPUImageBeautifyFilter BeautifyFaceDemo
最近需要给直播项目中添加美颜的功能,调研了很多SDK和开源代码(视决,涂图,七牛,金山云,videoCore等),综合成本/效果/对项目侵入性,最后决定使用一款基于GPUImage实现的 Beauti ...
- JavaScript -- 没事看看
@.delete 原文:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/delete
- vue 流程设计器
github地址:https://github.com/280780363/gucflow.designer demo地址:https://280780363.github.io/gucflow.de ...
- NSSrting的几种经常使用的使用方法
1.创建NSString字符串 NSString 与 char* 最大的差别就是 NSString是一个objective对象,而char* 是一个字节数组. @+" 字符串 " ...
- T-SQL高级查询语句(父子查询)
T-SQL高级查询语句 高级查询 1.连接查询,对结果集列的扩展 select * from info select * from info,nation #形成笛卡尔积 select * from ...
- lodash (js实用工具库)
是什么? 它提供了一整套函数式编程的实用功能, 并且支持模块化, 比underscore更优秀. 文档? http://lodashjs.com/docs/ 引用? <script src=&q ...
- LeetCode——Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...