Python爬虫(1) --基础知识

爬虫

  • 爬虫是什么? spider

是一种模仿浏览器上网过程的一种程序,可以获取一些网页的数据

基础知识

  • URL

统一资源定位符 uniform resource locator

bdce42aed53c6987a10545ea9e6a1e6.png

http: 超文本传输协议 HyperText Transfer Protocol 默认端口 80

https: 安全的超文本传输协议 security 默认端口 443

www.example.com 域名

80 端口 port

/path/to/myfile.html 资源路径

?key1=value1&key2=value2 参数 & 表示多个参数的拼接

# 锚点

  • 前端代码
<!DOCTYPE html> 声明为 HTML5 文档
<html>..</html> 是网页的根元素
<head>..</head> 元素包含了文档的元(meta)数据,如 <meta charset="utf-8"> 定义网页编码格式为 utf-8。
<title>..<title> 元素描述了文档的标题
<body>..</body> 表示用户可见的内容
<div>..</div> 表示框架
<p>..</p> 表示段落
<ul>..</ul> 定义无序列表
<ol>..</ol>定义有序列表
<li>..</li>表示列表项
<img src="" alt="">表示图片
<h1>..</h1>表示标题
<a href="">..</a>表示超链接
<!DOCTYPE html>
<html>
    <head>
        <!-- 内嵌样式 -->
        <style type="text/css">
        body{
            background-color:yellow;
        }
        p{
            font-size: 30px;
            color: springgreen;
        }
        </style>
        <meta charset="utf-8">
        <title>兰智数加学院</title>
    </head>
    <body>
        <a href="www.anhuisjxy.com">点击访问</a>
        <h1>兰智数加www.anhuisjxy.com</h1>
        <h2>Python爬虫</h2>
        <div>
            <p>认识网页结构</p>
            <ul>
                <li>HTML</li>
                <li>CSS</li>
            </ul>
        </div>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
        body{
            background-color: rgb(220, 226, 226);
        }
        </style>
        <meta charset="utf-8">
        <title>兰智数加学院</title>
    </head>
    <body>
        <h1 style="color: blue;">兰智数加www.anhuisjxy.com</h1>
        <h2>Python爬虫</h2>
        <p>点击下方按钮获取当前时间</p>
        <button onclick="DisplayDate()">点击这里</button>
        <p id="time" style="color: red;"></p>
        <!-- script标签内部编写js代码 -->
        <script>
            function DisplayDate(){
            document.getElementById("time").innerHTML=Date()
            }
        </script>
        </div>
    </body>
</html>

爬虫代码

  • 安装requests包
pip install requests
  • pip 换源
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/
pip config set install.trusted-host pypi.mirrors.ustc.edu.cn
  • User-Agent: 身份标识 表示你是哪个浏览器

相关推荐

  1. Python爬虫基础知识

    2024-07-20 09:56:02       38 阅读
  2. python爬虫基础知识

    2024-07-20 09:56:02       33 阅读
  3. python爬虫基础知识整理(2)

    2024-07-20 09:56:02       28 阅读
  4. Python爬虫——1爬虫基础(一步一步慢慢来)

    2024-07-20 09:56:02       11 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 09:56:02       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 09:56:02       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 09:56:02       45 阅读
  4. Python语言-面向对象

    2024-07-20 09:56:02       55 阅读

热门阅读

  1. 前端经验:使用sheetjs导出CSV文本为excel

    2024-07-20 09:56:02       17 阅读
  2. autohotkey自动化执行vim命令

    2024-07-20 09:56:02       20 阅读
  3. 开源虚拟加密盘VeraCrypt命令行使用方法

    2024-07-20 09:56:02       14 阅读
  4. DP 203 学习笔记

    2024-07-20 09:56:02       16 阅读
  5. python实现建立一个学生成绩管理系统

    2024-07-20 09:56:02       19 阅读
  6. redis是如何实现过期时间一到就删除key

    2024-07-20 09:56:02       20 阅读
  7. 从零开始!Jupyter Notebook的安装教程

    2024-07-20 09:56:02       16 阅读
  8. django命令

    2024-07-20 09:56:02       15 阅读
  9. 探索光影魔法:WebKit中的CSS文本阴影效果

    2024-07-20 09:56:02       14 阅读
  10. AI开源战争的真相

    2024-07-20 09:56:02       15 阅读
  11. AI测试入门(1):认识AI大语言模型(LLM)

    2024-07-20 09:56:02       16 阅读