一个爬虫前的配置及爬虫简示
来源:互联网 发布:淘宝丝袜4成是男的买的 编辑:程序博客网 时间:2024/04/30 09:14
采用Python3环境,并通过pip装几个包:
大概是我的系统环境变量没有设置好吧,我看网上都是直接pip install xxx,我的还要多加python -m 指令
设置好后,在python文件夹的Scripts里找到jupyter notebook.exe,打开,复制地址换浏览器需要输入服务器密码,按照网上教程我也没有修改成功,不知道原因,待解决吧。
右上角New-python3,开始编写属于你的第一个爬虫吧。
简单爬新浪网:
import requestsres = requests.get('http://mobile.sina.com.cn/')res.encoding = 'utf-8'print(res.text)
这里get的原理在 http://study.163.com/my 网络爬虫实战中讲到,选择Chrome浏览器,右键检查,选择Doc,在Preview可以查看内容(需要F5重新爬取),是否爬取到内容
其他小试:
from bs4 import BeautifulSouphtml_sample = '\<html> \ <head> \ <meta charset="utf-8"> \ <title></title> \ </head> \ <body> \ <h1> This is a test</h1> \ </body> \</html>'soup = BeautifulSoup(html_sample,'html.parser')header = soup.select('h1')print(header)print(header[0].text)
from bs4 import BeautifulSouphtml_sample = '\<!DOCTYPE html> \<html> \ <head> \ <meta charset="utf-8"> \ <title></title> \ </head> \ <body> \ <h1 id = "title">C++</h1> \ <h1 id = "title">Python</h1> \ <a href="#" class = "link"> This is link2 </a> \ </body> \</html> 'soup = BeautifulSoup(html_sample,'html.parser')alink = soup.select('#title')print(alink)print('\n')for link in alink: print(link)print('\n')for link in alink: print(link.text)
输出:
[<h1 id="title">C++</h1>, <h1 id="title">Python</h1>]<h1 id="title">C++</h1><h1 id="title">Python</h1>C++Python
0 0
- 一个爬虫前的配置及爬虫简示
- 一个简单的爬虫
- 一个简单的爬虫
- 一个爬虫的实现
- 一个简单的爬虫
- Python爬虫:学爬虫前得了解的事儿
- python爬虫入门教程(一):开始爬虫前的准备工作
- 一个爬虫
- 开源网络爬虫Larbin的安装及配置
- 开源网络爬虫Larbin的安装及配置
- 超好用的前嗅ForeSpider爬虫软件教程
- 排名前50个开源的Web爬虫
- 排名前50个开源的Web爬虫
- pyspider爬虫的一个应用
- 一个简单的爬虫(1)
- 一个简单的爬虫程序
- 一个简单的Python爬虫
- 一个简单的爬虫实验
- R语言扩展包dplyr——数据清洗和整理
- C++之对象指针
- 根据中序遍历和前序遍历构建二叉树
- python中的集合dict&set
- linux系统触摸板用不了(解决)
- 一个爬虫前的配置及爬虫简示
- PHP curl 超时时间设置
- SET DEFINE OFF prompt
- .net 大型分布式电子商务架构说明
- Linux学习篇之~unit5&unit6练习
- 自定义注解的学习与使用
- 文章标题
- 运动目标检测 混合高斯模型
- nginx 499 错误