zoukankan      html  css  js  c++  java
  • Python爬虫

    1.

    2.

     src 资源地址

    class  css中用来查找标签的属性,用来区分不同的盒子,爬虫中经常用到

    爬虫的设计思路

      三大特征

        1.网址 www.baidu.com

        2.协议 http  https(http+ss1)

        3.网页源代码

      爬虫思路

        1.请求网址,得到源代码

        2.解析源代码,拿到数据

        3.如果还存在其他网址,那么再次执行12

      爬虫模块

        requests 模块

          安装 (cmd调出运行安装)

            pip install requests

          使用(引入)

            import requests

          发起请求(get|post)

              get 正常使用 a标签 点击的请求,或者在地址栏中输入网址,直接回车的请求,表单提交时候能看到表单内容的请求

              post 在form表单中的method 属性设置,一般在模拟登陆的时候会用到post请求      

               发起get请求

                requests.get()

                                           

    import requests
    
    requests.get("https://www.baidu.com")

    当requests前边有空格是会提示unexpected indent 就是说“n”是一个“意外的”缩进

    import requests
    
    response=requests.get("https://www.baidu.com")
    print(response)
    print(type(response))

    返回值

    D:ProgramDataAnaconda3python.exe "E:/WXA/PyCharm study/爬虫介绍和基础库/demo1_requests请求.py"
    <Response [200]>
    <class 'requests.models.Response'>
    
    Process finished with exit code 0
    得到的r是一个response对象,还有一个状态码
    状态码简介
      1**正在请求
      2**请求成功
      3**网页重定向
      4**请求内容错误
      5**服务器错误
    返回值
      r.text 返回网页的源代码
  • 相关阅读:
    做问答系统是对题目修改的bug
    控件treetable使用
    百度地图API --地理位置定位
    按每十分钟查询数据
    《deetom》项目开发历程<六> 免登陆
    poj 3348
    poj 1556
    poj 1269
    poj 3304
    R 540
  • 原文地址:https://www.cnblogs.com/smile502/p/12697645.html
Copyright © 2011-2022 走看看