为了账号安全,请及时绑定邮箱和手机立即绑定

Python开发简单爬虫

蚂蚁帅帅 全栈工程师
难度初级
时长 1小时14分
学习人数
综合评分9.67
646人评价 查看评价
9.9 内容实用
9.6 简洁易懂
9.5 逻辑清晰
  • 爬虫调度器:启动、停止、监视爬虫运行情况; URL管理器:将要爬取的URL和已经爬取的URL 网页下载器:URL管理器将将要爬取的URL传送给网页下载器下载下来; 网页解析器:将网页下载器下载的网页的内容传递给网页解析器解析; (1)、解析出新的URL传递给URL管理器; (2)、解析出有价值的数据; 上面三个形成了一个循环,只要网页解析器有找到新的URL,就一直执行下去;
    查看全部
  • 这个地方有点问题,应该是"/view/\d+.htm"
    查看全部
  • 这里提供下python3.4.4实现网页下载器的方法: import urllib.request from http.cookiejar import CookieJar url = 'http://www.baidu.com' print('第一种方法') res1 = urllib.request.urlopen(url) print(res1.getcode()) print(len(res1.read())) print('第二种方法') request = urllib.request.Request(url, headers={'user-agent': 'Mozilla/5.0'}) res2 = urllib.request.urlopen(request) print(res2.getcode()) print(len(res2.read())) print('第三种方法') cj = CookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) urllib.request.install_opener(opener) res3 = urllib.request.urlopen(url) print(res3.getcode()) print(cj) print(res3.read())
    查看全部
  • aaas
    查看全部
  • import urllib2 res=urllib2.urlopen(url) code=res.getcode() content=res.read()
    查看全部
  • 爬虫调度端:启动,停止,监控运行情况; URL管理器:管理待爬取和已爬取的URL; 网页下载器:接收待爬取URL,将网页内容下载为字符串,给解析器; 网页解析器:一方面解析出有价值的数据,一方面解析出其他关联URL,传回URL管理器进行循环。
    查看全部
  • 视屏中的练习程序 import urllib2 import cookielib import bs4 url = "http://www.baidu.com" print '11---------------------------' response1 = urllib2.urlopen(url) print response1.getcode() print len(response1.read()) print '22----------------------------' request = urllib2.Request(url) request.add_header("user-agent", "Mozilla/5.0") response2 = urllib2.urlopen(request) print response1.getcode() print len(response1.read()) print '33------------------------------' cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) response3 = urllib2.urlopen(url) print response3.getcode() print len(response3.read()) print bs4
    查看全部
  • class UrlManager(object): #初始化两个集合 def __init__(self): self.new_urls = set() self.old_urls = set() def add_new_url(self, url): ''' 向URL管理器中添加一个新的URL ''' if url is None: return if url not in self.add_new_urls and url not in self.old_urls: self.new_urls.add(url) def add_new_urls(self, urls): ''' 向URL管理器中批量添加新的URL ''' if urls is None or len(urls) == 0: return for url in urls: self.add_new_url(url) def has_new_url(self): ''' 判断URL管理器中是否有新的待爬取的URL ''' return len(self.new_urls) != 0 def get_new_url(self): ''' 从URL管理器中获取一个新的带爬取的URL ''' #返回一个URL并从中移除这条URL new_url = self.new_urls.pop() self.old_urls.add(new_url) return new_url
    查看全部
    1 采集 收起 来源:URL管理器

    2016-01-09

  • 简单爬虫架构-运行流程
    查看全部
  • 开发爬虫步骤:<br> 确定目标;(目的是防止抓取不需要的网页,浪费感情)<br> 分析目标;(URL格式、数据格式、网页编码)<br> 编写代码<br> 执行爬虫 注意:如果网站结构发生升级,那么抓取策略也需要升级!!!!
    查看全部
  • #coding:utf-8; import urllib2; import cookielib; print "======第一种方法===========" url = "http://www.baidu.com"; response1 = urllib2.urlopen(url); print response1.getcode(); print len(response1.read()); print "=======第二种方法======"; request = urllib2.Request(url); request.add_header("userAgent","Mozilla/5.0"); response2 = urllib2.urlopen(request); print response2.getcode(); print len(response2.read()); print "=======第三种方法======"; cj = cookielib.CookieJar(); opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)); urllib2.install_opener(opener); response3 = urllib2.urlopen(url); print response3.getcode(); print cj; print len(response3.read());
    查看全部
  • class HtmlOutputer(object): def __init__(self): self.datas=[]#列表 #收集数据 def collect_data(self,data): if data is None: return self.datas.append(data) #输出HTML内容 def output_html(self): fout=open('output.html','w')#输出到output.html中,w为写模式 fout.write("<html>") fout.write("<body>") fout.write("<table>") #ASCI for data in self.datas: fout.write("<tr>") fout.write("<td>s%</td>" % data["url"]) fout.write("<td>s%</td>" % data["title"].encode("UTF-8")) fout.write("<td>s%</td>" % data["summary"].encode("UTF-8")) fout.write("</tr>") fout.write("</table>") fout.write("</body>") fout.write("</html>")
    查看全部
    1 采集 收起 来源:HTML输出器

    2018-03-22

  • 网页解析器都是正则封装的。 python解析器:parser, beautifel soap,LXML java: parser ,jsoup
    查看全部
  • 实例爬虫
    查看全部
  • 很多干干脆脆换个风格
    查看全部

举报

0/150
提交
取消
课程须知
本课程是Python语言开发的高级课程 1、Python编程语法; 2、HTML语言基础知识; 3、正则表达式基础知识;
老师告诉你能学到什么?
1、爬虫技术的含义和存在价值 2、爬虫技术架构 3、组成爬虫的关键模块:URL管理器、HTML下载器和HTML解析器 4、实战抓取百度百科1000个词条页面数据的抓取策略设定、实战代码编写、爬虫实例运行 5、一套极简的可扩展爬虫代码,修改本代码,你就能抓取任何互联网网页!

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!