PYTHON爬虫(爬虫的基本原理)

一 爬虫的概念

二 爬虫的步骤

1 发起请求

  • 请求方法:get/post
  • 请求url:统一资源定位符
  • 请求头:请求配置
  • 请求体:post

2 获取响应

  • 常见的状态码:200/301(重定向)/404(找不到资源)/502(服务器内部出错)
  • 响应头
  • 响应体

3 解析内容

  • 直接处理
  • json解析
  • 正则
  • 美丽汤
  • pyquery
  • xpath
  • js渲染的解决方法:分析ajax请求,selenium(webdriver),splash

4 结构化存储

  • 文本、二进制和数据库

三 爬虫常用模块

  • urllib re

  • requests

  • phantomjs

  • lxml

  • beautifulsoup4

  • selenium

  • pyquery

  • pymysql

  • redis

  • flask

  • django

  • jupyter

猜你喜欢

转载自blog.csdn.net/stanwuc/article/details/81909173