找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 26514|回复: 5

[文本处理] 批处理如何从多个文本读取变量?

[复制链接]
发表于 2017-5-21 23:42:04 | 显示全部楼层 |阅读模式
请教各位大神
使用curl提交信息 需要从4个文本里读取数据
每个文本文件的内容
1.txt
1
2
3

2.txt
a
b
c

3.txt
A
B
C

4.txt



需要的效果
curl -d "1=1&2=a&3=A&4=黑"
curl -d "1=2&2=b&3=B&4=白"
curl -d "1=3&2=c&3=C&4=灰"
发表于 2017-5-22 14:31:37 | 显示全部楼层
test.ps1
  1. $a1 = Get-Content 1.txt
  2. $a2 = Get-Content 2.txt
  3. $a3 = Get-Content 3.txt
  4. $a4 = Get-Content 4.txt
  5. for($i=0; $i -lt $a1.Count; $i++){
  6.     curl -d "1=$a1[$i]&2=$a2[$i]&3=$a3[$i]&4=$a4[$i]"
  7. }
复制代码
 楼主| 发表于 2017-5-22 21:07:48 | 显示全部楼层
回复 2# ShowCode


多谢大神 弱弱的问   
这是powershell么?能用批处理做么?
发表于 2017-5-22 21:54:59 | 显示全部楼层
python3版,模仿楼上的写法。
不用curl
用pip install requests 安装requests。
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on 2017-05-22 21:38:48

  4. @author: codegay
  5. """
  6. import requests

  7. txt1 = [r.rstrip() for r in open("1.txt").read()]
  8. txt2 = [r.rstrip() for r in open("2.txt").read()]
  9. txt3 = [r.rstrip() for r in open("3.txt").read()]
  10. txt4 = [r.rstrip() for r in open("4.txt").read()]


  11. url = 'http://bathome.net'

  12. data = zip(txt1,txt2,txt3,txt4)
  13. session = requests.sessions()

  14. for t1,t2,t3,t4 in zip(txt1,txt2,txt3,txt4):
  15.     data = {1:t1,2:t2,3:t3,4:t4}
  16.     session.post(url,data=data)
复制代码
 楼主| 发表于 2017-5-22 22:23:33 | 显示全部楼层
回复 4# codegay


    谢谢   还是想求个批处理
这个需求是丰富现有的工具  全部推倒重来工程太大。重点是我技术有限只会些简单的批处理。
发表于 2017-5-22 22:32:38 | 显示全部楼层
回复 5# zhiweiloli


    →_→ 和我没关系。我也不在乎。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 21:52 , Processed in 0.018538 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表