Published: 18 Apr 2020 › Updated: 18 Apr 2020
python爬虫基础篇
简介
python爬虫是一种非常方便实用的一种方式用来抓取网页信息以及数据,接下来我通过一个非常简单基础的爬取豆瓣电影实例来体会其中的强大之处。
准备工作
Pycharm IDE
requests, lxml库
xpath语法
首先就是导入requests,lxml库
由于每个网站都会有一定的反爬虫机制,在爬取时候需要做一些处理去构造用户标识头User-Agent
在网页中右键检查就可以查看网页完整的源代码,这里通过xpath的语法找到电影信息在li标签下面,可以直接通过//ul[='lists']/li找到对应的信息
最后通过遍历得到我们所需要的爬虫数据并且打印出来
打印结果
成功输出了得到的电影数据
Leave python爬虫基础篇 to:
Read more #cn-malaysia posts
Best Posts From luzihang
We have not curated any of luzihang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.