get_text) #返回除标签外的纯文本
PyQuery:也是解析工具,提供与jquery(几年前非常火热的java script框架)类似的语法解析html同样也支持css选择器,安装方式如下。
1. 相关链接
Github:https://github.com/gawel/pyquery
PyPI:https://pypi.python.org/pypi/pyquery
官方文档:http://pyquery.readthedocs.io
2. 我们仍然使用conda指令安装,但同时也可以使用pip3指令安装,在终端输入如下代码中的一个安装即可
#使用 conda安装
conda install pyquery
#使用 pip3安装
pip3 install pyquery
tesserocr:可以用来识别验证码或者图片的OCR(光学字符识别)解析库,它是对python API的封装,所以安装它需要先安装tesseract,它们的安装方式如下
1. 相关链接
tesserocr Github:https://github.com/sirfz/tesserocr
tesserocr PyPI:https://pypi.python.org/pypi/tesserocr
tesseract 下载地址:http://digi.bib.uni-mannheim.de/tesserocr
tesseract Github:https://github.com/tesseract-ocr/tesseract
tesseract 语言包:https://github.com/tesseract-oct/tessdata
tesseract 文档:https://github.com/tesseract-ocr/tesseract/wiki/Documentation
2. 我们现需要使用brew指令安装ImageMagick和tesseract库,然后再使用conda指令安装tesserocr库,在终端中按次序输入以下代码即可
# 安装ImageMagick
brew install imagemagick
# 安装 tesseract
brew install tesseract --all-languages
# 安装 tesserocr
conda install tesserocr
3. 安装好后,我们可以在程序中测试它是否能正确运行,代码如下
import tesserocr
from PTL import Image
image = Image.open('example.jpeg')
print(tesserocr.image_to_text(image)) #将图片中的文字转换为字符串
好了至此,与python爬虫相关的基础库已经安装完成了,本文中并未涉及scrapy库的安装。因为个人认为还是先不要使用框架自己编写爬虫更能提升自己的编码能力,谢谢大家的阅读!