https://www.cnblogs.com/lanyinhao/p/9634742.html 比较全面

1、模块说明

requests是使用Apache2 licensed 许可证的HTTP库。

用python编写。

比urllib2模块更简洁。

Request支持HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动响应内容的编码,支持国际化的URL和POST数据自动编码。

在python内置模块的基础上进行了高度的封装,从而使得python进行网络请求时,变得人性化,使用Requests可以轻而易举的完成浏览器可有的任何操作。

现代,国际化,友好。

requests会自动实现持久连接keep-alive

2、基础入门

1)导入模块

  1. import requests

2)发送请求的简洁

  示例代码:获取一个网页(个人github)

  1. import requests
  2.  
  3. r = requests.get('https://github.com/Ranxf') # 最基本的不带参数的get请求
  4. r1 = requests.get(url='http://dict.baidu.com/s', params={'wd': 'python'}) # 带参数的get请求

我们就可以使用该方式使用以下各种方法

  1. 1 requests.get(‘https://github.com/timeline.json’) # GET请求
  2. 2 requests.post(“http://httpbin.org/post”) # POST请求
  3. 3 requests.put(“http://httpbin.org/put”) # PUT请求
  4. 4 requests.delete(“http://httpbin.org/delete”) # DELETE请求
  5. 5 requests.head(“http://httpbin.org/get”) # HEAD请求
  6. 6 requests.options(“http://httpbin.org/get” ) # OPTIONS请求

3)为url传递参数

  1. >>> url_params = {'key':'value'} # 字典传递参数,如果值为None的键不会被添加到url中
  2. >>> r = requests.get('your url',params = url_params)
  3. >>> print(r.url)
  4.   your url?key=value

4)响应的内容

  1. r.encoding #获取当前的编码
  2. r.encoding = 'utf-8' #设置编码
  3. r.text #以encoding解析返回内容。字符串方式的响应体,会自动根据响应头部的字符编码进行解码。
  4. r.content #以字节形式(二进制)返回。字节方式的响应体,会自动为你解码 gzip 和 deflate 压缩。
  5.  
  6. r.headers #以字典对象存储服务器响应头,但是这个字典比较特殊,字典键不区分大小写,若键不存在则返回None
  7.  
  8. r.status_code #响应状态码
  9. r.raw #返回原始响应体,也就是 urllib 的 response 对象,使用 r.raw.read()
  10. r.ok # 查看r.ok的布尔值便可以知道是否登陆成功
  11. #*特殊方法*#
  12. r.json() #Requests中内置的JSON解码器,以json形式返回,前提返回的内容确保是json格式的,不然解析出错会抛异常
  13. r.raise_for_status() #失败请求(非200响应)抛出异常

post发送json请求:

  1. 1 import requests
  2. 2 import json
  3. 3
  4. 4 r = requests.post('https://api.github.com/some/endpoint', data=json.dumps({'some': 'data'}))
  5. 5 print(r.json())

5)定制头和cookie信息

  1. header = {'user-agent': 'my-app/0.0.1''}
  2. cookie = {'key':'value'}
  3. r = requests.get/post('your url',headers=header,cookies=cookie)
  1. data = {'some': 'data'}
  2. headers = {'content-type': 'application/json',
  3. 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
  4.  
  5. r = requests.post('https://api.github.com/some/endpoint', data=data, headers=headers)
  6. print(r.text)

6)响应状态码

使用requests方法后,会返回一个response对象,其存储了服务器响应的内容,如上实例中已经提到的 r.text、r.status_code……
获取文本方式的响应体实例:当你访问 r.text 之时,会使用其响应的文本编码进行解码,并且你可以修改其编码让 r.text 使用自定义的编码进行解码。

  1. 1 r = requests.get('http://www.itwhy.org')
  2. 2 print(r.text, '\n{}\n'.format('*'*79), r.encoding)
  3. 3 r.encoding = 'GBK'
  4. 4 print(r.text, '\n{}\n'.format('*'*79), r.encoding)

示例代码:

  1. 1 import requests
  2. 2
  3. 3 r = requests.get('https://github.com/Ranxf') # 最基本的不带参数的get请求
  4. 4 print(r.status_code) # 获取返回状态
  5. 5 r1 = requests.get(url='http://dict.baidu.com/s', params={'wd': 'python'}) # 带参数的get请求
  6. 6 print(r1.url)
  7. 7 print(r1.text) # 打印解码后的返回数据

运行结果:

  1. /usr/bin/python3.5 /home/rxf/python3_1000/1000/python3_server/python3_requests/demo1.py
  2. 200
  3. http://dict.baidu.com/s?wd=python
  4. …………
  5.  
  6. Process finished with exit code 0
  1. r.status_code #如果不是200,可以使用 r.raise_for_status() 抛出异常

7)响应

  1. r.headers #返回字典类型,头信息
  2. r.requests.headers #返回发送到服务器的头信息
  3. r.cookies #返回cookie
  4. r.history #返回重定向信息,当然可以在请求是加上allow_redirects = false 阻止重定向

8)超时

  1. r = requests.get('url',timeout=1) #设置秒数超时,仅对于连接有效

9)会话对象,能够跨请求保持某些参数

  1. s = requests.Session()
  2. s.auth = ('auth','passwd')
  3. s.headers = {'key':'value'}
  4. r = s.get('url')
  5. r1 = s.get('url1')

10)代理

  1. proxies = {'http':'ip1','https':'ip2' }
  2. requests.get('url',proxies=proxies)

汇总:

  1. # HTTP请求类型
  2. # get类型
  3. r = requests.get('https://github.com/timeline.json')
  4. # post类型
  5. r = requests.post("http://m.ctrip.com/post")
  6. # put类型
  7. r = requests.put("http://m.ctrip.com/put")
  8. # delete类型
  9. r = requests.delete("http://m.ctrip.com/delete")
  10. # head类型
  11. r = requests.head("http://m.ctrip.com/head")
  12. # options类型
  13. r = requests.options("http://m.ctrip.com/get")
  14.  
  15. # 获取响应内容
  16. print(r.content) #以字节的方式去显示,中文显示为字符
  17. print(r.text) #以文本的方式去显示
  18.  
  19. #URL传递参数
  20. payload = {'keyword': '香港', 'salecityid': '2'}
  21. r = requests.get("http://m.ctrip.com/webapp/tourvisa/visa_list", params=payload)
  22. printr.url #示例为http://m.ctrip.com/webapp/tourvisa/visa_list?salecityid=2&keyword=香港
  23.  
  24. #获取/修改网页编码
  25. r = requests.get('https://github.com/timeline.json')
  26. print r.encoding
  27.  
  28. #json处理
  29. r = requests.get('https://github.com/timeline.json')
  30. printr.json()) # 需要先import json
  31.  
  32. # 定制请求头
  33. url = 'http://m.ctrip.com'
  34. headers = {'User-Agent' : 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'}
  35. r = requests.post(url, headers=headers)
  36. print r.request.headers)
  37.  
  38. #复杂post请求
  39. url = 'http://m.ctrip.com'
  40. payload = {'some': 'data'}
  41. r = requests.post(url, data=json.dumps(payload)) #如果传递的payload是string而不是dict,需要先调用dumps方法格式化一下
  42.  
  43. # post多部分编码文件
  44. url = 'http://m.ctrip.com'
  45. files = {'file': open('report.xls', 'rb')}
  46. r = requests.post(url, files=files)
  47.  
  48. # 响应状态码
  49. r = requests.get('http://m.ctrip.com')
  50. print(r.status_code)
  51.  
  52. # 响应头
  53. r = requests.get('http://m.ctrip.com')
  54. print (r.headers)
  55. print (r.headers['Content-Type'])
  56. print (r.headers.get('content-type')) #访问响应头部分内容的两种方式
  57.  
  58. # Cookies
  59. url = 'http://example.com/some/cookie/setting/url'
  60. r = requests.get(url)
  61. r.cookies['example_cookie_name'] #读取cookies
  62.  
  63. url = 'http://m.ctrip.com/cookies'
  64. cookies = dict(cookies_are='working')
  65. r = requests.get(url, cookies=cookies) #发送cookies
  66.  
  67. #设置超时时间
  68. r = requests.get('http://m.ctrip.com', timeout=0.001)
  69.  
  70. #设置访问代理
  71. proxies = {
  72. "http": "http://10.10.1.10:3128",
  73. "https": "http://10.10.1.100:4444",
  74. }
  75. r = requests.get('http://m.ctrip.com', proxies=proxies)
  76.  
  77. #如果代理需要用户名和密码,则需要这样:
  78. proxies = {
  79. "http": "http://user:pass@10.10.1.10:3128/",
  80. }
  1. # HTTP请求类型
  2. # get类型
  3. r = requests.get('https://github.com/timeline.json')
  4. # post类型
  5. r = requests.post("http://m.ctrip.com/post")
  6. # put类型
  7. r = requests.put("http://m.ctrip.com/put")
  8. # delete类型
  9. r = requests.delete("http://m.ctrip.com/delete")
  10. # head类型
  11. r = requests.head("http://m.ctrip.com/head")
  12. # options类型
  13. r = requests.options("http://m.ctrip.com/get")
  14.  
  15. # 获取响应内容
  16. print(r.content) #以字节的方式去显示,中文显示为字符
  17. print(r.text) #以文本的方式去显示
  18.  
  19. #URL传递参数
  20. payload = {'keyword': '香港', 'salecityid': '2'}
  21. r = requests.get("http://m.ctrip.com/webapp/tourvisa/visa_list", params=payload)
  22. printr.url #示例为http://m.ctrip.com/webapp/tourvisa/visa_list?salecityid=2&keyword=香港
  23.  
  24. #获取/修改网页编码
  25. r = requests.get('https://github.com/timeline.json')
  26. print r.encoding
  27.  
  28. #json处理
  29. r = requests.get('https://github.com/timeline.json')
  30. printr.json()) # 需要先import json
  31.  
  32. # 定制请求头
  33. url = 'http://m.ctrip.com'
  34. headers = {'User-Agent' : 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'}
  35. r = requests.post(url, headers=headers)
  36. print r.request.headers)
  37.  
  38. #复杂post请求
  39. url = 'http://m.ctrip.com'
  40. payload = {'some': 'data'}
  41. r = requests.post(url, data=json.dumps(payload)) #如果传递的payload是string而不是dict,需要先调用dumps方法格式化一下
  42.  
  43. # post多部分编码文件
  44. url = 'http://m.ctrip.com'
  45. files = {'file': open('report.xls', 'rb')}
  46. r = requests.post(url, files=files)
  47.  
  48. # 响应状态码
  49. r = requests.get('http://m.ctrip.com')
  50. print(r.status_code)
  51.  
  52. # 响应头
  53. r = requests.get('http://m.ctrip.com')
  54. print (r.headers)
  55. print (r.headers['Content-Type'])
  56. print (r.headers.get('content-type')) #访问响应头部分内容的两种方式
  57.  
  58. # Cookies
  59. url = 'http://example.com/some/cookie/setting/url'
  60. r = requests.get(url)
  61. r.cookies['example_cookie_name'] #读取cookies
  62.  
  63. url = 'http://m.ctrip.com/cookies'
  64. cookies = dict(cookies_are='working')
  65. r = requests.get(url, cookies=cookies) #发送cookies
  66.  
  67. #设置超时时间
  68. r = requests.get('http://m.ctrip.com', timeout=0.001)
  69.  
  70. #设置访问代理
  71. proxies = {
  72. "http": "http://10.10.1.10:3128",
  73. "https": "http://10.10.1.100:4444",
  74. }
  75. r = requests.get('http://m.ctrip.com', proxies=proxies)
  76.  
  77. #如果代理需要用户名和密码,则需要这样:
  78. proxies = {
  79. "http": "http://user:pass@10.10.1.10:3128/",
  80. }

3、示例代码

GET请求

  1. 1 # 1、无参数实例
  2. 2
  3. 3 import requests
  4. 4
  5. 5 ret = requests.get('https://github.com/timeline.json')
  6. 6
  7. 7 print(ret.url)
  8. 8 print(ret.text)
  9. 9
  10. 10
  11. 11
  12. 12 # 2、有参数实例
  13. 13
  14. 14 import requests
  15. 15
  16. 16 payload = {'key1': 'value1', 'key2': 'value2'}
  17. 17 ret = requests.get("http://httpbin.org/get", params=payload)
  18. 18
  19. 19 print(ret.url)
  20. 20 print(ret.text)

POST请求

  1. # 1、基本POST实例
  2.  
  3. import requests
  4.  
  5. payload = {'key1': 'value1', 'key2': 'value2'}
  6. ret = requests.post("http://httpbin.org/post", data=payload)
  7.  
  8. print(ret.text)
  9.  
  10. # 2、发送请求头和数据实例
  11.  
  12. import requests
  13. import json
  14.  
  15. url = 'https://api.github.com/some/endpoint'
  16. payload = {'some': 'data'}
  17. headers = {'content-type': 'application/json'}
  18.  
  19. ret = requests.post(url, data=json.dumps(payload), headers=headers)
  20.  
  21. print(ret.text)
  22. print(ret.cookies)

请求参数

 请求参数
 参数示例代码

json请求:

  1. #! /usr/bin/python3
  2. import requests
  3. import json
  4.  
  5. class url_request():
  6. def __init__(self):
  7. ''' init '''
  8.  
  9. if __name__ == '__main__':
  10. heard = {'Content-Type': 'application/json'}
  11. payload = {'CountryName': '中国',
  12. 'ProvinceName': '四川省',
  13. 'L1CityName': 'chengdu',
  14. 'L2CityName': 'yibing',
  15. 'TownName': '',
  16. 'Longitude': '107.33393',
  17. 'Latitude': '33.157131',
  18. 'Language': 'CN'}
  19. r = requests.post("http://www.xxxxxx.com/CityLocation/json/LBSLocateCity", heards=heard, data=payload)
  20. data = r.json()
  21. if r.status_code!=200:
  22. print('LBSLocateCity API Error' + str(r.status_code))
  23. print(data['CityEntities'][0]['CityID']) # 打印返回json中的某个key的value
  24. print(data['ResponseStatus']['Ack'])
  25. print(json.dump(data, indent=4, sort_keys=True, ensure_ascii=False)) # 树形打印json,ensure_ascii必须设为False否则中文会显示为unicode

Xml请求:

  1. #! /usr/bin/python3
  2. import requests
  3.  
  4. class url_request():
  5. def __init__(self):
  6. """init"""
  7.  
  8. if __name__ == '__main__':
  9. heards = {'Content-type': 'text/xml'}
  10. XML = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Request xmlns="http://tempuri.org/"><jme><JobClassFullName>WeChatJSTicket.JobWS.Job.JobRefreshTicket,WeChatJSTicket.JobWS</JobClassFullName><Action>RUN</Action><Param>1</Param><HostIP>127.0.0.1</HostIP><JobInfo>1</JobInfo><NeedParallel>false</NeedParallel></jme></Request></soap:Body></soap:Envelope>'
  11. url = 'http://jobws.push.mobile.xxxxxxxx.com/RefreshWeiXInTokenJob/RefreshService.asmx'
  12. r = requests.post(url=url, heards=heards, data=XML)
  13. data = r.text
  14. print(data)

状态异常处理

  1. import requests
  2.  
  3. URL = 'http://ip.taobao.com/service/getIpInfo.php' # 淘宝IP地址库API
  4. try:
  5. r = requests.get(URL, params={'ip': '8.8.8.8'}, timeout=1)
  6. r.raise_for_status() # 如果响应状态码不是 200,就主动抛出异常
  7. except requests.RequestException as e:
  8. print(e)
  9. else:
  10. result = r.json()
  11. print(type(result), result, sep='\n')

上传文件

使用request模块,也可以上传文件,文件的类型会自动进行处理:

  1. import requests
  2.  
  3. url = 'http://127.0.0.1:8080/upload'
  4. files = {'file': open('/home/rxf/test.jpg', 'rb')}
  5. #files = {'file': ('report.jpg', open('/home/lyb/sjzl.mpg', 'rb'))} #显式的设置文件名
  6.  
  7. r = requests.post(url, files=files)
  8. print(r.text)

request更加方便的是,可以把字符串当作文件进行上传:

  1. import requests
  2.  
  3. url = 'http://127.0.0.1:8080/upload'
  4. files = {'file': ('test.txt', b'Hello Requests.')} #必需显式的设置文件名
  5.  
  6. r = requests.post(url, files=files)
  7. print(r.text)

6) 身份验证

基本身份认证(HTTP Basic Auth)

  1. import requests
  2. from requests.auth import HTTPBasicAuth
  3.  
  4. r = requests.get('https://httpbin.org/hidden-basic-auth/user/passwd', auth=HTTPBasicAuth('user', 'passwd'))
  5. # r = requests.get('https://httpbin.org/hidden-basic-auth/user/passwd', auth=('user', 'passwd')) # 简写
  6. print(r.json())

另一种非常流行的HTTP身份认证形式是摘要式身份认证,Requests对它的支持也是开箱即可用的:

  1. requests.get(URL, auth=HTTPDigestAuth('user', 'pass')

Cookies与会话对象

如果某个响应中包含一些Cookie,你可以快速访问它们:

  1. import requests
  2.  
  3. r = requests.get('http://www.google.com.hk/')
  4. print(r.cookies['NID'])
  5. print(tuple(r.cookies))

要想发送你的cookies到服务器,可以使用 cookies 参数:

  1. import requests
  2.  
  3. url = 'http://httpbin.org/cookies'
  4. cookies = {'testCookies_1': 'Hello_Python3', 'testCookies_2': 'Hello_Requests'}
  5. # 在Cookie Version 0中规定空格、方括号、圆括号、等于号、逗号、双引号、斜杠、问号、@,冒号,分号等特殊符号都不能作为Cookie的内容。
  6. r = requests.get(url, cookies=cookies)
  7. print(r.json())

会话对象让你能够跨请求保持某些参数,最方便的是在同一个Session实例发出的所有请求之间保持cookies,且这些都是自动处理的,甚是方便。
下面就来一个真正的实例,如下是快盘签到脚本:

  1. import requests
  2.  
  3. headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  4. 'Accept-Encoding': 'gzip, deflate, compress',
  5. 'Accept-Language': 'en-us;q=0.5,en;q=0.3',
  6. 'Cache-Control': 'max-age=0',
  7. 'Connection': 'keep-alive',
  8. 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
  9.  
  10. s = requests.Session()
  11. s.headers.update(headers)
  12. # s.auth = ('superuser', '123')
  13. s.get('https://www.kuaipan.cn/account_login.htm')
  14.  
  15. _URL = 'http://www.kuaipan.cn/index.php'
  16. s.post(_URL, params={'ac':'account', 'op':'login'},
  17. data={'username':'****@foxmail.com', 'userpwd':'********', 'isajax':'yes'})
  18. r = s.get(_URL, params={'ac':'zone', 'op':'taskdetail'})
  19. print(r.json())
  20. s.get(_URL, params={'ac':'common', 'op':'usersign'})

requests模块抓取网页源码并保存到文件示例

这是一个基本的文件保存操作,但这里有几个值得注意的问题:

1.安装requests包,命令行输入pip install requests即可自动安装。很多人推荐使用requests,自带的urllib.request也可以抓取网页源码

2.open方法encoding参数设为utf-8,否则保存的文件会出现乱码。

3.如果直接在cmd中输出抓取的内容,会提示各种编码错误,所以保存到文件查看。

4.with open方法是更好的写法,可以自动操作完毕后释放资源

  1. #! /urs/bin/python3
  2. import requests
  3.  
  4. '''requests模块抓取网页源码并保存到文件示例'''
  5. html = requests.get("http://www.baidu.com")
  6. with open('test.txt', 'w', encoding='utf-8') as f:
  7. f.write(html.text)
  8.  
  9. '''读取一个txt文件,每次读取一行,并保存到另一个txt文件中的示例'''
  10. ff = open('testt.txt', 'w', encoding='utf-8')
  11. with open('test.txt', encoding="utf-8") as f:
  12. for line in f:
  13. ff.write(line)
  14. ff.close()

因为在命令行中打印每次读取一行的数据,中文会出现编码错误,所以每次读取一行并保存到另一个文件,这样来测试读取是否正常。(注意open的时候制定encoding编码方式)

接口请求:get、post (requests方法)的更多相关文章

  1. Requests方法 -- 参数关联与JSESSION(上一个接口的返回数据作为下一个接口的请求参数)

    前言 参数关联是接口测试和性能测试最为重要的一个步骤,很多接口的请求参数是动态的,并且需要从上一个接口的返回值里面取出来,一般只能用一次就失效了.最常见的案例就是网站的登录案例,很多网站的登录并不仅仅 ...

  2. 【python接口自动化】- 使用requests库发送http请求

    前言:什么是Requests ?Requests 是⽤Python语⾔编写,基于urllib,采⽤Apache2 Licensed开源协议的 HTTP 库.它⽐ urllib 更加⽅便,可以节约我们⼤ ...

  3. 接口测试框架实战(一) | Requests 与接口请求构造

    1080×388 33.4 KB Requests 是一个优雅而简单的 Python HTTP 库,其实 Python 内置了用于访问网络的资源模块,比如urllib,但是它远不如 Requests ...

  4. C# 动态创建SQL数据库(二) 在.net core web项目中生成二维码 后台Post/Get 请求接口 方式 WebForm 页面ajax 请求后台页面 方法 实现输入框小数多 自动进位展示,编辑时实际值不变 快速掌握Gif动态图实现代码 C#处理和对接HTTP接口请求

    C# 动态创建SQL数据库(二) 使用Entity Framework  创建数据库与表 前面文章有说到使用SQL语句动态创建数据库与数据表,这次直接使用Entriy Framwork 的ORM对象关 ...

  5. 接口调试之Postman 使用方法详解

    一.Postman背景介绍 用户在开发或者调试网络程序或者是网页B/S模式的程序的时候是需要一些方法来跟踪网页请求的,用户可以使用一些网络的监视工具比如著名的Firebug等网页调试工具.今天给大家介 ...

  6. Requests方法 -- cookie绕过验证码登录操作

    前言有些登录的接口会有验证码:短信验证码,图形验证码等,这种登录的话验证码参数可以从后台获取的(或者查数据库最直接).获取不到也没关系,可以通过添加 cookie 的方式绕过验证码. 1.这里以登录博 ...

  7. python接口自动化(响应对象方法)

    python接口自动化(响应对象方法) 一.encoding作用 获取请求的编码(在不设置响应编码时,响应的信息默认使用的是请求的编码格式):r.encoding 设置响应的编码:r.encoding ...

  8. Requests方法 -- Blog流程类进行关联

    1.接口封装关联 1.有些接口经常会用到比如登录的接口,这时候我们可以每个接口都封装成一个方法,如:登录.保存草稿.发帖.删帖,这四个接口就可以写成四个方法2.接口封装好了后,后面我们写用例那就直接调 ...

  9. Postman - 功能强大的 API 接口请求调试和管理工具

    Postman 是一款功能强大的的 Chrome 应用,可以便捷的调试接口.前端开发人员在开发或者调试 Web 程序的时候是需要一些方法来跟踪网页请求的,用户可以使用一些网络的监视工具比如著名的 Fi ...

随机推荐

  1. (转)GNU风格ARM汇编语法指南(非常详细)5

    原文地址:http://zqwt.012.blog.163.com/blog/static/120446842010111482417545/ 6.GNU汇编程序中的常数 <1>    十 ...

  2. 【Linux】linux系统管理---好用的一些开源工具

    目录 linux系统管理---好用的一些开源工具 htop dstat Glances iftop nethogs iotop linux系统管理---好用的一些开源工具 htop htop是一款运行 ...

  3. Map-->HashMap练习(新手)

    //导入的包.import java.util.*;//创建的一个类.public class zylx1 { //公共静态的主方法. public static void main(String[] ...

  4. java-根据用户输入的成绩来判断等级(新手)

    //创建的一个包名. package qige; //导入的一个包.import java.util.Scanner; //定义一个类.public class Zy2 { //公共静态的主方法. p ...

  5. Natas11 Writeup(常见编码、异或逆推、修改cookie)

    Natas11: 页面提示cookie被异或加密保护,查看源码,发现了一个预定义参数和三个函数. //预定义参数,猜测将showpassword设置为yes即可得到密码. $defaultdata = ...

  6. scrapy框架xpath的几点说明

    1.xpath返回的是一个列表 2.调用Selector对象的extract方法将返回选中内容的Unicode字符串 SelectorList对象调用extract_first() 方法会返回其中第一 ...

  7. 为什么Mysql的常用引擎都默认使用B+树作为索引?

    一.前言 为了讲清楚这个问题,我们要先了解什么是索引. 我记得刚刚学习数据库的时候,老师喜欢用书本的目录来类比数据库的索引,并告诉我们索引能够像目录一样,让我们更快地找到想要找到的数据. 如果是第一次 ...

  8. Selenium IDE安装及简介

    一.Selenium IDE安装 Selenium IDE是Firefox浏览器的一个插件,依附于Firefox浏览器.在网上搜了Selenium IDE的安装教程,大部分都是说在官网下载安装,其实最 ...

  9. Contest 152

    2019-09-01 20:59:55 总体感受:最近几次参加contest发现自己的水平还是严重的不够,尤其是在处理一些异常情况的时候,遇到TLE,MLE如何有效的进行Debug是需要去锻炼的. 注 ...

  10. mysql数据库中的mybatis中xml解决in不起作用的问题

    在sql语句中,某个字段进行in条件的时候,不起作用, 但是执行语句查询为null数据,但是根据表中数据来看是不可能有null数据的可能性的,所以不知道什么原因导致数据出不来 我因此想到以下解决办法来 ...