【发布时间】:2013-09-19 14:44:28
【问题描述】:
大家好,我对 python 还很陌生,我需要你们的帮助。
import sys, http.client
file = open('out.txt', 'w')
showlines = 50
npa = []
try:
servername = sys.argv[1]
except:
servername = 'localcallingguide.com'
server = http.client.HTTPConnection(servername)
for i in range(1000):
if i < 10:
npa.append('00' + str(i))
elif i >= 10 and i < 100:
npa.append('0' + str(i))
else:
npa.append(str(i))
for i in range(len(npa)):
filename = '/lca_rcdist.php?npa1=503&nxx1=745&npa2=503&nxx2=' + npa[i]
server.putrequest('GET', filename)
server.putheader('Accept', 'text/html')
server.endheaders()
reply = server.getresponse()
if reply.status != 200:
print('Error sending request', reply.status, reply.reason)
else:
data = reply.readlines()
reply.close()
for line in data[:showlines]:
cLine = line.decode('utf-8')
if '"ofrom">N<' in cLine:
file.write('NXX ,' + npa[i])
file.close
使用上面的脚本,我得到“NXX、503、NXX、203 等的输出,我需要从输出中隐藏 NXX,知道如何在不删除脚本的 NXX 的情况下做到这一点。
先谢谢了!
【问题讨论】:
-
只是一个建议:如果您需要帮助,最好提供更多(更准确)的细节。例如,您的代码会生成类似“NXX ,503”而不是“NXX 503”的输出。你想要另一个输出,但不想更改脚本是什么意思?等等……
-
问题没有意义。如果你不想在输出中出现 NXX,就不要写了。
-
我更新了整个脚本,我确实从脚本中删除了 NXX,但我正在为其编辑脚本的人说我不能这样做
-
"我需要你的帮助。" 欢迎来到 Stack Overflow!虽然我们确实尽力提供帮助,但 StackOverflow 不是支持论坛。这是一个问答网站。一般的模式是你提出一个问题,其他读者回答它。我注意到您的帖子中没有问题。请告诉我们您尝试了什么,特别是哪些不适合您。然后问我们一个问题,如果得到回答,可能会推动您实现目标。
-
我的问题是,有没有一种不同的方法来打印输出,其中包含从 localcallingguide.com 提取的所有信息而没有前导 NXX,我只需要分隔区号但输出中的逗号