Python 网络爬虫与信息获取(二)—— 页面内容提取
2017-07-31 11:21
501 查看
1. 获取超链接
python获取指定网页上所有超链接的方法links = re.findall(b’”((http|ftp)s?://.*?)”’, html)
links = re.findall(b’href=”(.*?)”’)
html 为 url 返回的 html 内容,可通过以下方式获取
html = urllib.request.urlopen(url).read()
html = requests.get().text
2. 下载指定文件到指定路径
比如我们要爬取http://courses.cs.vt.edu/~cs2704/fall01/Notes/链接下的所有 pdf 文件:
#coding: UTF-8 import requests from urllib import request import re import os url = 'http://courses.cs.vt.edu/~cs2704/fall01/Notes/' r = requests.get(url) files = re.findall('href="(.*?)"', r.text) for file in files[1:]: request.urlretrieve(os.path.join(url, file), os.path.join('D:/data/', file))
相关文章推荐
- python网络爬虫学习(一)通过GET和POST方式获取页面内容
- python---get请求https的页面,并获取html返回的内容信息
- Python网络爬虫与信息提取 - 内容导学与开发工具选择
- Python网络爬虫与信息提取-Day7-基于bs4库的HTML内容遍历方法
- Python网络爬虫与信息提取(一):网络爬虫之规则
- Python实现可获取网易页面所有文本信息的网易网络爬虫功能示例
- Python+Selenium 自动化实现实例-获取页面元素信息
- Python网络爬虫与信息提取-Day11-正则表达式的概念和语法
- 【MOOC】Python网络爬虫与信息提取-北京理工大学-part 1
- 【MOOC】Python网络爬虫与信息提取-北京理工大学-part 2
- Python网络爬虫与信息提取(二):网络爬虫之提取
- Python PhatomJS 和Selenium动态加载页面 获取图片内容
- 中国大学MOOC·Python网络爬虫与信息提取(一)
- Python网络爬虫与信息提取-中国大学MOOC
- Python网络爬虫与信息提取(一)
- [Python] (多线程版本)抓取聚划算页面商品分析页面获取商品信息并以XML格式保存到本地
- Python网络爬虫与信息提取(三):网络爬虫之实战
- Python_selenium之获取当前页面的href属性,id属性,图片信息和截全屏
- python获取远程页面内容,避免卡死问题
- C++和python如何获取百度搜索结果页面下信息对应的真实链接(百度搜索爬虫,可指定页数)