我是靠谱客的博主 苹果紫菜,最近开发中收集的这篇文章主要介绍Python爬虫学习(爬虫基础知识,Beautifulsoup的使用)Python爬虫,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Python爬虫

文章目录

  • Python爬虫
    • 爬虫基础知识
      • 环境搭配
      • 获取一个get请求
      • 获得一个post请求
      • 超时处理
      • 进行伪装(伪装成浏览器爬取网页)
    • Beautifulsoup的使用
      • 准备工作
      • Tag标签
      • NavigableString
      • BeautifulSoup
      • Comment
      • 文档的遍历
      • 文档的搜索
        • 字符串过滤
        • 正则表达式搜索
        • kwargs 参数
        • text参数
        • limit参数
      • css选择器
      • 正则表达式
        • 简单使用

爬虫基础知识

环境搭配

# @author  VV
# @date  2021/8/14 19:34
import urllib.request
import urllib.parse

获取一个get请求

获取一个get请求
response = urllib.request.urlopen("http://www.baidu.com")
print(response.read().decode('utf-8'))

获得一个post请求

data=bytes(urllib.parse.urlencode({
   "hello":"world"}),encoding="utf-8")
response = urllib.request.urlopen("http://www.httpbin.org/post",data=data)
print(response.read().decode("utf-8"))

超时处理

try:
    response = urllib.request.urlopen("http://www.httpbin.org/get"

最后

以上就是苹果紫菜为你收集整理的Python爬虫学习(爬虫基础知识,Beautifulsoup的使用)Python爬虫的全部内容,希望文章能够帮你解决Python爬虫学习(爬虫基础知识,Beautifulsoup的使用)Python爬虫所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部