python get,post方法使用

示例网站:

http://exercise.kingname.info/exercise_requests_get.html

​​​​​​GET 测试 (kingname.info)icon-default.png?t=M4ADhttp://exercise.kingname.info/exercise_requests_get.htmlpython get,post方法使用_第1张图片

import requests

html = requests.get('http://exercise.kingname.info/exercise_requests_get.html').content.decode()
print(html)

post方法的简单使用;

使用get方法访问post网页时的报错

import requests

html = requests.get('http://exercise.kingname.info/exercise_requests_post').content.decode()
print(html)

python get,post方法使用_第2张图片

改用post方法来对网页进行访问

mport requests
import re
data = {'name':'liyong','password':'li123'}
html = requests.post('http://exercise.kingname.info/exercise_requests_post',data=data).content.decode()
html_data = re.finall()
print(html)

 

python get,post方法使用_第3张图片

 

改为json格式提交数据

import requests
import re
data = {'name':'liyong','password':'li123'}
html = requests.post('http://exercise.kingname.info/exercise_requests_post',json=data).content.decode()
#html_data = re.finall()
print(html)

python get,post方法使用_第4张图片

使用正则表达式提取数据

import requests
import re
data = {'name':'liyong','password':'li123'}
html = requests.post('http://exercise.kingname.info/exercise_requests_post',json=data).content.decode()
html_title = re.findall('title>(.*?)<',html,re.S)
html_data = re.findall('p>(.*?)<',html,re.S)
content = '\n'.join(html_data)
print("title is :",html_title)
print("data is :",content)
#print(html)

python get,post方法使用_第5张图片

 

 

你可能感兴趣的:(python,python,开发语言)