Python测试Post请求

原有:

#coding:utf-8

import requests

def request(title, content):
datas = {"title":title,"content":content}
r = requests.post('http://10.9.197.193:18080/cms/api/paraphrasing/para',data=datas)
print(str(r.status_code) + ":" + r.content) # title="*花莲附近海域发生6.5级地震"
# content="新华社台北2月7日电(记者李凯)据中国地震台网中心网站消息,6日23时50分,*花莲县附近海域发生6.5级地震,震中位于北纬24.13度、东经121.71度,震源深度11.0公里。\n台气象部门称,6日23时50分,*花莲近海发生6.0级地震。\n" # test_file = "/home/czj/1-data/NLP/1_NLP/1-data/context2/rpt_sinaent.txt"
test_file = "/home/czj/tmp5/news_0323aa"
visited_num = 6768
n = 0
for line in open(test_file, "r"): n += 1
if n <= visited_num:
continue;
print ">>>" + str(n) fields = line.split("\t\t")
if len(fields) != 3:
continue
news = fields[2]
segs = news.split("  ")
if len(segs) < 2:
continue
title = segs[0].strip()
content = ""
for i in range(1, len(segs)):
content += segs[i].strip()
request(title, content)

现用:

#! /usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ = "NYA" import requests
import json def request(title,content):
datas = {title:content}
r = requests.post("http://172.18.6.46:18080/search/query",data=datas)
print (str(r.status_code) + ":" + r.content) i = 0
for line in open("/home/han/niuya/videoList.txt"):
if(i>999):
line = line.strip()
print i + 1
print line
title = "path"
content = line
request(title,content)
print "-------------------------------------------------------------------------------------------------------------"
i += 1
上一篇:[转载]《民航科技》2012年4月专家论坛:罗喜伶《SWIM技术国际研究动态及对中国民航的借鉴意义》


下一篇:自动适配H5容器(UIViewView/WKWebView),生成长图,防微信进度条