爬虫入门知识整理

学习爬虫预备知识:

HTML入门
http://www.runoob.com/html/html-intro.html
信息标记格式:XML JSON YAML 入门
https://www.cnblogs.com/beiyin/archive/2018/06/03/9129443.html
爬虫入门:
https://www.cnblogs.com/lisenlin/p/9905514.htm
https://gitbook.cn/books/59b541bb3d49c37f032b67f1/index.html
正则表达式入门:
https://www.cnblogs.com/sunny3096/p/7201403.html
python爬虫入门–Beautiful Soup库介绍及实例、信息标记三种格式举例:好
https://blog.csdn.net/i_chaoren/article/details/63282877

robots分析
robots协议分析——以亚马逊(中国)为例
https://www.jianshu.com/p/bf34d1d32548
robots协议分析——以淘宝)为例
https://www.jianshu.com/p/a3ad1cdd9e3e
robots简介与书写方法
https://wenku.baidu.com/view/ca3d6424cdbff121dd36a32d7375a417866fc1cd.html
设置user agent 伪装自己
https://blog.csdn.net/asialee_bird/article/details/79810297

BeautifulSoup中的find,find_all
https://www.cnblogs.com/keye/p/7868059.html

爬虫–Python常用模块之requests,urllib和re:爬虫的基本步骤
https://www.cnblogs.com/lisenlin/p/9905514.html

爬虫的步骤:

1.发起请求,模拟浏览器发送一个http请求,获取响应的信息,包括状态、网页编码、网页内容等
2.解析内容并提取出自己所需的部分
3.保存数据至文件、数据库等

爬虫实现方案之一:适用于正则表达式的初学者
需要导入以下库:
import re
import requests
from bs4 import BeautifulSoup
第一步:使用requests库的requests.get()发出http请求,返回一个response对象,该对象包含响应信息包括状态、网页编码、网页内容等
MyRes=requests.get(‘http://www.baidu.com’)
第二步:使用bs4库的BeautifulSoup模块解析网页内容,形成一个树结构soup对象。
MySoup=BeautifulSoup(MyRes.text,‘html.parser’)
第三步:提取所需信息
MySoup.find() 与MySoup.findall() re.compile(正则表达式) 三者相结合
第四步:利用文件或数据库的写方法将提取的信息写入。

常用的方法如下:
 
创建BeautifulSoup对象
soup=BeatifulSoup(html)
print(type(soup))

BeautifulSoup 对象的常用属性
title Strings stripped_strings

查找tag的函数
find_all(name, attrs, recursive, text, **kwargs)
find(name, attrs, recursive, text, **kwargs)

获取tag对象
tag=soup.head.title
print(tag)

Beautiful Soup Documentation -Beautiful Soup 4.4.0 documentation

Tag对象的常用属性
name attrs contents string

Tag中数据的获取函数
get(attribute)
get_text()

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值