Python3.4编程实现简单抓取爬虫功能示例


Posted in Python onSeptember 14, 2017

本文实例讲述了Python3.4编程实现简单抓取爬虫功能。分享给大家供大家参考,具体如下:

import urllib.request
import urllib.parse
import re
import urllib.request,urllib.parse,http.cookiejar
import time
def getHtml(url):
  cj=http.cookiejar.CookieJar()
  opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
  opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'),('Cookie','4564564564564564565646540')]
  urllib.request.install_opener(opener)
  page = urllib.request.urlopen(url)
  html = page.read()
  return html
#print ( html)
#html = getHtml("http://weibo.com/")
def getimg(html):
  html = html.decode('utf-8')
  reg='"screen_name":"(.*?)"'
  imgre = re.compile(reg)
  src=re.findall(imgre,html)
  return src
#print ("",getimg(html))
uid=['2808675432','3888405676','2628551531','2808587400']
for a in list(uid):
  print (getimg(getHtml("http://weibo.com/"+a)))
  time.sleep(1)

更多关于Python相关内容可查看本站专题:《Python Socket编程技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

Python 相关文章推荐
python实现dnspod自动更新dns解析的方法
Feb 14 Python
python MySQLdb Windows下安装教程及问题解决方法
May 09 Python
讲解Python中运算符使用时的优先级
May 14 Python
python追加元素到列表的方法
Jul 28 Python
python 捕获shell脚本的输出结果实例
Jan 04 Python
Window环境下Scrapy开发环境搭建
Nov 18 Python
python实现对任意大小图片均匀切割的示例
Dec 05 Python
Django渲染Markdown文章目录的方法示例
Jan 02 Python
OpenCV 边缘检测
Jul 10 Python
Python使用mongodb保存爬取豆瓣电影的数据过程解析
Aug 14 Python
详解python的内存分配机制
May 10 Python
python自动获取微信公众号最新文章的实现代码
Jul 15 Python
python实现八大排序算法(1)
Sep 14 #Python
python实现简单聊天应用 python群聊和点对点均实现
Sep 14 #Python
Python实现购物系统(示例讲解)
Sep 13 #Python
python模块之sys模块和序列化模块(实例讲解)
Sep 13 #Python
python模块之time模块(实例讲解)
Sep 13 #Python
python difflib模块示例讲解
Sep 13 #Python
Python网络编程 Python套接字编程
Sep 13 #Python
You might like
通过文字传递创建的图形按钮
2006/10/09 PHP
ubuntu10.04配置 nginx+php-fpm模式的详解
2013/06/03 PHP
file_get_contents("php://input", "r")实例介绍
2013/07/01 PHP
PHPExcel中文帮助手册|PHPExcel使用方法(分享)
2017/06/09 PHP
PHP数据分析引擎计算余弦相似度算法示例
2017/08/08 PHP
php strftime函数的详细用法
2018/06/21 PHP
JQuery获取元素文档大小、偏移和位置和滚动条位置的方法集合
2010/01/12 Javascript
让ie6也支持websocket采用flash封装实现
2013/02/18 Javascript
JavaScript中的常见问题解决方法(乱码,IE缓存,代理)
2013/11/28 Javascript
jQuery aminate方法定位到页面具体位置
2013/12/26 Javascript
javascript 回到顶部效果的实现代码
2014/02/17 Javascript
nodejs命令行参数处理模块commander使用实例
2014/09/17 NodeJs
Nodejs中读取中文文件编码问题、发送邮件和定时任务实例
2015/01/01 NodeJs
javascript和jQuery中的AJAX技术详解【包含AJAX各种跨域技术】
2016/12/15 Javascript
javascript 删除数组元素和清空数组的简单方法
2017/02/24 Javascript
Node.js设置CORS跨域请求中多域名白名单的方法
2017/03/28 Javascript
JavaScript中splice与slice的区别
2017/05/09 Javascript
Bootstrap + AngularJS 实现简单的数据过滤字符查找功能
2017/07/27 Javascript
详解Vue单元测试Karma+Mocha学习笔记
2018/01/31 Javascript
JS对象与json字符串相互转换实现方法示例
2018/06/14 Javascript
node.js自动上传ftp的脚本分享
2018/06/16 Javascript
DWR内存兼容及无法调用问题解决方案
2020/10/16 Javascript
[19:59]2014DOTA2国际邀请赛 IG战队纪录片
2014/08/07 DOTA
python在windows下实现ping操作并接收返回信息的方法
2015/03/20 Python
python中使用mysql数据库详细介绍
2015/03/27 Python
解析Mac OS下部署Pyhton的Django框架项目的过程
2016/05/03 Python
python与mysql数据库交互的实现
2020/01/06 Python
Python更换pip源方法过程解析
2020/05/19 Python
tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this T
2020/06/22 Python
解决python的空格和tab混淆而报错的问题
2021/02/26 Python
CSS3中动画属性transform、transition和animation属性的区别
2016/09/25 HTML / CSS
农行实习自我鉴定
2013/09/22 职场文书
公务员职务工作的自我评价
2013/11/01 职场文书
汽车装潢店创业计划书范文
2014/02/05 职场文书
校园主题婚礼活动策划方案
2014/09/15 职场文书
先进个人申报材料
2014/12/30 职场文书