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

Python开发简单爬虫

蚂蚁帅帅 全栈工程师
难度初级
时长 1小时14分
学习人数
综合评分9.67
646人评价 查看评价
9.9 内容实用
9.6 简洁易懂
9.5 逻辑清晰
  • 图片下载: url="*.jpeg" #找到图片的完整链接 response=urllib2.urlopen(url) f=open("image.jpeg",'wb') f.write(response.read()) f.close() 如: #coding:utf8 import urllib2 def download_img(url): response=urllib2.urlopen(url) content=response.read() f=open("img.png",'wb') f.write(content) f.close() if __name__=="__main__": url=raw_input("Input the path of image:") download_img(url) 运行代码后,输入一个图片的完整URL,如: http://img1.joyreactor.cc/pics/post/%D0%BA%D1%80%D0%B0%D1%81%D0%B8%D0%B2%D1%8B%D0%B5-%D0%BA%D0%B0%D1%80%D1%82%D0%B8%D0%BD%D0%BA%D0%B8-%D0%BF%D0%B5%D1%81%D0%BE%D1%87%D0%BD%D0%B8%D1%86%D0%B0-%D0%BA%D1%80%D0%B0%D1%81%D0%B8%D0%B2%D1%8B%D1%85-%D0%BA%D0%B0%D1%80%D1%82%D0%B8%D0%BD%D0%BE%D0%BA-art-Skyrim-575783.png 即可下载图片(要注意图片的编码,即图片的后缀一致)
    查看全部
  • class是python的关键字,在find中做元素需要在后面加上下划线
    查看全部
  • 爬虫架构3大模块: URL管理器(管理将要抓取的URL) 网络下载器 urllib2(将给定的URL网页内容下载到本地,以便后续操作) 网络解析器beautifulsoup(通过解析得到想要的内容)
    查看全部
  • 爬虫可以从一个特定的url出发,访问它所关联的所有的url
    查看全部
    1 采集 收起 来源:爬虫是什么

    2017-01-19

  • 爬虫架构中的三大模块: url管理器(管理将要抓取的和已经抓取过的url); 网页下载器urllib2(将给定的url的网页内容下载到本地,以便后续的分析); 网页解析器beautifulsoup(通过解析得到我们想要的内容)。
    查看全部
  • 开发爬虫实例: 一、步骤 1、确定目标:确定抓取哪个网站的哪些网页的哪部分数据。本实例确定抓取百度百科python词条页面以及它相关的词条页面的标题和简介。 2、分析目标:确定抓取数据的策略。一是分析要抓取的目标页面的URL格式,用来限定要抓取的页面的范围;二是分析要抓取的数据的格式,在本实例中就是要分析每一个词条页面中标题和简介所在的标签的格式;三是分析页面的编码,在网页解析器中指定网页编码,才能正确解析。 3、编写代码:在解析器中会使用到分析目标步骤所得到的抓取策略的结果。 4、执行爬虫。
    查看全部
  • import urllib2, cookielib url = 'http://www.baidu.com' print '111111111111111' re1=urllib2.urlopen(url) print re1.getcode() cont = re1.read() #print cont print len(re1.read()) print '22222222222222222' request = urllib2.Request(url) request.add_header('User-Agent', 'Mozilla/5.0') re2=urllib2.urlopen(url) print re2.getcode() cont2 = re2.read() #print cont2 print len(re2.read()) print '333333333333333333' cj=cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) re3=urllib2.urlopen(url) print re3.getcode() cont3 = re3.read() #print cont3 print cj print len(re3.read())
    查看全部
  • 简单爬虫架构: 爬虫调度端:启动爬虫、停止爬虫、监视爬虫运行情况。 爬虫程序: URL管理器:管理将要爬取的URL和已经爬取的URL。从中可以取出一个待爬取的URL传送给网页下载器。 网页下载器:将URL指定的网页下载下来存储成一个字符串,并把字符串传送给网页解析器进行解析。 网页解析器:一是解析出我们需要的有价值的数据;二是解析出该网页中的指向其他网页的URL,补充进URL管理器。 三个模块形成循环,只要有相关联的URL,就一直运行下去。
    查看全部
  • python爬虫真强大
    查看全部
    1 采集 收起 来源:课程总结

    2016-11-20

  • Ctrl+1 提示导入re模块包 //import re
    查看全部
  • 简单架构
    查看全部
  • import urllib.request import http.cookiejar url = 'http://www.zerospace.cc' # 直接访问网页 response = urllib.request.urlopen(url) print(response.getcode()) # 带浏览器信息访问 request = urllib.request.Request(url) request.add_header('user-agent', 'Mozilla/5.0') response = urllib.request.urlopen(request) print(response.getcode()) # 带Cookie信息访问 cookie = http.cookiejar.CookieJar() request = urllib.request.HTTPCookieProcessor(cookie) request = urllib.request.build_opener(request) urllib.request.install_opener(request) response = urllib.request.urlopen(url) print(response.getcode())
    查看全部
  • # coding:utf8 __author__ = 'xray' import urllib2 import cookielib url = "https://rollbar.com/docs/" print '第一种方法' response1 = urllib2.urlopen(url) print response1.getcode() print len(response1.read()) print '第二种方法' request = urllib2.Request(url) request.add_header("user-agent", "Mozilla/5.0") response2 = urllib2.urlopen(request) print response2.getcode() print response2.read() print '第三种方法' cj = cookielib.CookiJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) response3 = urllib2.urlopen(url) print response3.getcode() print cj print response3.read()
    查看全部
  • # coding:utf-8 from bs4 import BeautifulSoup import re print("Python3 的代码如下") html_doc = """ 因字数限制,省略。请到 http://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-the-tree 复制吧 """ soup = BeautifulSoup(html_doc, 'html.parser') print("获取所有的链接") links = soup.find_all('a') for link in links: print(link.name, link['href'], link.get_text()) print("获取lacie的链接") link_node = soup.find('a', href="http://example.com/lacie") print(link_node.name, link_node['href'], link_node.get_text()) print("正则匹配") link_node = soup.find('a', href=re.compile(r"ill")) print(link_node.name, link_node['href'], link_node.get_text()) print("获取p段落文字") p_node = soup.find('p', class_="title") print(p_node.name, p_node.get_text())
    查看全部
  • 运行流程
    查看全部

举报

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

微信扫码,参与3人拼团

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

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