zoukankan      html  css  js  c++  java
  • python3: requests模块的使用;

    requests库常用于http请求,可以很方便对网页进行爬取;

    主要方法(七个):

    方法解释
    requests.request() 构造一个请求,支持以下各种方法
    requests.get() 获取html的主要方法
    requests.head() 获取html头部信息的主要方法
    requests.post() 向html网页提交post请求的方法
    requests.put() 向html网页提交put请求的方法
    requests.patch() 向html提交局部修改的请求
    requests.delete() 向html提交删除请求

    1.requests.get

    原型:  

      r = requests.get(url,params, **kwargs)

      url: 网站地址;

      params: 参数, 额外参数,可以使字典或者字节流

      **kwargs: 12个控制访问的参数( 这里不讲述);

     响应response对象有以下属性:

    属性说明
    r.status_code http请求的返回状态,若为200则表示请求成功。
    r.text http响应内容的字符串形式,即返回的页面内容
    r.encoding 从http header 中猜测的相应内容编码方式
    r.apparent_encoding 从内容中分析出的响应内容编码方式(备选编码方式)
    r.content http响应内容的二进制形式

    其他略(请见: https://blog.csdn.net/gyq1998/article/details/78583841)

  • 相关阅读:
    shell cut
    查询表名
    RandomAccessFile
    eclipse 背景颜色
    JAVA 获取分行符
    date time insert
    shell date time
    python
    gdg shell
    shell入门之变量测试
  • 原文地址:https://www.cnblogs.com/yinwei-space/p/9320820.html
Copyright © 2011-2022 走看看