支持url批量发post请求的python工具是什么?
有个几十万行的文本文件,里面逐行有一些信息
有没有什么工具可以给某个url批量按照文本文件一行行发post请求呢?
求具体说明
一个写的比一个短你们这是逼我啊 ... 要比拼 Hello World 么 ..?
awk '{ system( "curl -d \"data=" $0 "\" http://url" ) }' file.txt
awk 单行搞定 ...
试试apache的ab,或者类似的siege, http_load
nodejs:
lineArray = [] request = require 'request' lineArray.forEach (line)-> request.post line
这种事情太适合用PYTHON来实现了。简单的代码如下:
text = open("__init__.py") import urllib while True: line = text.readline() if not line: break params = urllib.urlencode({'arg': line}) f = urllib.urlopen("http://UrUrl", params) print f.read() text.close()
如果需要的话还可以加入连接超时然后重新发起请求,还可以使用多线程来减少整个的时间。
你们为什么一定要比短....
wget -b -q -O /dev/null --post-data="" -i urls_file
有轮子的时候用轮子 ... 没有轮子的时候就自己造一个轮子好了 ...
好吧其实我就是突然有一点点闲时间可以帮你写写代码这样 ...
<?php /* put your text file location here ... */ define( 'TEXT_SRC', '/path/to/your.text.file.txt' ); /* put the url which you wanna post data to here ... */ define( 'DATA_URL', 'http://the.url.data/goes.to' ); /* put post field name here ... */ define( 'POST_PFX', 'data' ); /* read million data from source ... */ $text_src = file( TEXT_SRC, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); /* hey here comes cURL ... */ $curl = curl_init(); /* prepare cURL and make a very fashion UA header ... */ curl_setopt_array( $curl, [ CURLOPT_URL => DATA_URL, CURLOPT_USERAGENT => 'Mozilla/1.22 (compatible; MSIE 2.0; Windows 3.1)', CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, ] ); /* something to handle cURL result ... */ $callback = function( $result ) { return; }; /* time for our BIG LOOOOOOOP ! */ foreach( $text_src as $data ) { /* fill data ... */ curl_setopt( $curl, CURLOPT_POSTFIELDS, POST_PFX . '=' . $data ); /* and send them out ! */ $callback( curl_exec( $curl ) ); } /* you have had a long flight ... time for rest ... */ curl_close( $curl );
运行的话需要 php 5.4.0 以上的版本和 cURL 扩展 ... 前三行是配置区需要自行修改 ...
另外程序是以牺牲内存为代价提升效率的 ... 因为我觉得说只有几十万行的话应该文件不会太大 ...
程序会把那个文本文档一股脑读进内存 ... 所以如果要处理更多数据的话还要修改 ...
恩 ... 就是这样 ... 看看是不是你想要的效果呢 ..?
不太清楚你说的是一次 HTTP 请求还是多次请求。如果需要一次请求发送几十万行的文本数据,中间非常容易断掉。如果是多次请求,每次请求发送一行文本数据,可以试试看 curl 。不同的编程语言都有不同的实现方法,具体请查阅对应语言的官方文档。
js: for(var i=0;i<n;++i){window.open(url);}
import requests file = open("text.txt") for text in file.readlines(): data = {"data":text} resp = requests.get(url=url, data=data) print resp.text file.close()
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd20301.html
相关文章 Recommend
- • django中url无法include怎么配置?
- • Flask中的URL部分什么方法可以让它支持正则
- • python web框架webpy urls对应表在修改之后不会立即生
- • 用python方法截获来访者信息有什么框架支持?
- • Python sqlalchemy批量数据插入优化注意事项有哪些
- • python有支持内存保存SQL查询依然可用的功能吗
- • 有哪些支持C语言的流化程序(类似protobuf/thirft这种
- • python 解析网页不出来
- • python用urlopen返回 HTTP Error 400,用curl正常
- • Python支持调用其它语言函数吗?例如C++代码或Jav
- • python tornado url斜杠补全如何定义
- • Python中将文本转换为二进制文件有什么方法可以
必知PYTHON教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
必知PYTHON模块 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • django app提供pv信息的方法是什么
- • Django项目版本升级如何操作?
- • django较多数据传递如何优雅的呈现
- • django1.7获取参数问题求助
- • Django1.7使用内置comment遇到问题
- • python mysql数据库做insert操作时报_mysql_ex
- • 关于python mysql的duplicate insert机制的疑问
- • pymongo使用insert函数批量插入被中断要怎么
- • Python程序员解决棘手问题的常用库
- • 求助关于restfull api接口几个问题
图文精华 RECOMMEND
-
django1.7获取参数问题求助
-
Python程序员解决棘手问题的常用库
-
求问str()同__str__原理上有什么不同
-
scrapy框架里面用link extractor怎么能
-
python {}.fromkeys创建字典append添加操
-
python3 类型Type str doesn't support th
热点文章 HOT
- 学习Python有什么好的书籍推荐?
- Python匿名函数 Lambda表达式作用
- Python与Java、C、Ruby、PHP等编程语言有什么
- Python 正则中文网页字符串提取问题
- 如何为实时性应用存取经纬度?django my
- 想用python做个客户端,在二维码登录这个地
- 有让IDE可识别Python函数参数类型的方法吗
- Python字符串转换成列表正则疑问