zoukankan      html  css  js  c++  java
  • requests 可以玩接口自动化测试,爬虫也是可以滴

    import requests
    #1.带参的get请求:
    url ='URL_你的'
    requests.get(url,params={"key":"value"})
    #带参的post请求(表单提交):
    requests.post(url,data={"key1":"value1","key2":"value2"})
    #josn参数提交:
    requests.post(url,json={"key1":"value1","key2":"value2"})
    response = requests.get(url)
    print(response.headers) # 头head
    print(response.text)  #body,直接从网络上面抓取的数据,经过编码打印出来
    print(response.content)  #直接从网络上面抓取的数据,没有经过任何解码
    print(response.json()) #json 直接从网络上面抓取的数据,转换成字典模式展示
    print(response.json()['key'])# 查字典的方式展示一个value
    print(response.status_code) #请求状态码
    print(response.reason) #状态码的含义
    print(response.elapsed) #请求响应时间
    print(response.request)  #查看api请求信息是什么请求方式
    print(response.encoding)  #查看内容编码
    print(response.raw.read(100000))  #查看前10字节的内容

    记录额外小知识1,大神绕道:

    from selenium import webdriver
    import time
    import urllib.request
    driver = webdriver.Chrome()
    driver.get('http://www.l99.com/EditText_view.action?textId=9458460')
    time.sleep(2)
    for i in range(1,16):
        yuansu = '//*[@id="db_postion_49735813"]/div/div[1]/div/p[' + str(i) + ']/span/img'
        print(yuansu)
        yuansu = driver.find_element_by_xpath(yuansu)
        attribute=yuansu.get_attribute("src")#取元素的元素值,这里取的就是图片的打开地址
        print(attribute)
        path_my='C:\Users\Administrator\Desktop\qq\'+str(i)+'.jpg'
        urllib.request.urlretrieve(attribute,path_my)
    driver.close()

    记录额外小知识2,大神绕道:

    import urllib.request
    # 网络上图片的地址
    img_src = 'http://s10.sinaimg.cn/mw690/002FPe2pgy6ZLAOby0p29&690'
    path_my='C:\Users\Administrator\Desktop\qq\qqq.jpg'
    urllib.request.urlretrieve(img_src,path_my)
  • 相关阅读:
    20155333 《网络对抗》 Exp6 信息搜集与漏洞扫描
    20155333 《网络对抗》 Exp5 MSF基础应用
    20155333 《网络对抗》Exp4 恶意代码分析
    20155333 《网络对抗》Exp3 免杀原理与实践
    20155333 《网络对抗》Exp2 后门原理与实践
    2017-2018-2 20155333 《网络对抗技术》 Exp1 PC平台逆向破解
    2017-2018-1 20155333 《信息安全系统设计基础》第三周学习总结
    内核模块实践实验报告
    Linux内核期末总结
    Linux内核期中
  • 原文地址:https://www.cnblogs.com/Mr-Simple001/p/10540667.html
Copyright © 2011-2022 走看看