我有一个具有以下格式的代理txt文件:
102.129.249.120:3128
102.129.249.120:8080
101.4.136.34:8080
103.228.117.244:8080
etc
我想创建一个bash脚本,将(例如)做的事:curl -x "$IP" google.com
。
不幸的是,curl给我所有代理不支持的代理语法。
有任何想法吗?
顺便说一句,我真的怀疑这个问题是否已经重复,因为我尝试了其他所有方法都无济于事。
我的剧本:
Number=$(wc -l < ProxyList.txt)
for ((i=1;i<=$Number;++i)) do
ip=$(head -n ${i} ProxyList.txt | tail -n +${i})
curl -p -x "$ip" 'webpage' -H 'user-agent' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Cookie: wpml_referer_url=referer; _icl_current_language=es; PHPSESSID=tpikve1vl4ued06i082vprqdo1' -H 'If-Modified-Since: Mon, 16 May 2016 07:27:13 GMT' -H 'If-None-Match: "3d6-532f08d9d7640-gzip"' -H 'Cache-Control: max-age=0' -m 6
done
我的代理服务器列表的一个小样本:
102.129.249.120:3128
102.129.249.120:8080
101.4.136.34:8080
103.228.117.244:8080
103.253.27.108:80
104.45.188.43:3128
104.250.34.179:80
105.27.238.161:80
104.154.143.77:3128
110.243.20.2:9999
111.68.26.237:8080
106.104.151.142:58198
113.252.95.19:8197
115.231.31.130:80
118.69.50.154:80
118.69.50.154:443
119.81.189.194:80
119.81.189.194:8123
119.81.199.81:8123
119.81.199.83:8123
119.81.199.80:8123
12.139.101.100:80
12.139.101.101:80
119.81.199.85:31288
119.81.199.86:8123
119.81.199.87:8123
12.139.101.102:80
124.156.98.172:443
13.228.91.252:3128
138.197.157.32:3128
138.197.157.32:8080
138.68.240.218:8080
138.68.240.218:3128
138.68.60.8:8080
138.68.60.8:3128
输入文件的每行末尾都有回车符。
输入文件中的每一行都以\r\n
而不是结束\n
。
您可以通过以下方式进行检查od
:
$ head -1 ProxyList.txt | od -c
0000000 1 0 2 . 1 2 9 . 2 4 9 . 1 2 0 :
0000020 3 1 2 8 \r \n
0000026
因此,在您的脚本中,$ip
值实际上为102.129.249.120:3128\r
。
您可以删除\r
字符,tr
例如:
while read proxy; do
curl -p -x $proxy $webpage
done < <( tr -d '\r' < ProxyList.txt )
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句