【发布时间】:2017-02-23 13:12:56
【问题描述】:
我目前正在尝试从 10 个 url 的 .txt 文件中提取原始数据,并将每一行(URL)的原始数据放入 .txt 文件中。然后使用 Python 对处理后的数据(去除 html 的同一原始 .txt 文件中的原始数据)重复该过程。
import commands
import os
import json
# RAW DATA
input = open('uri.txt', 'r')
t_1 = open('command', 'w')
counter_1 = 0
for line in input:
counter_1 += 1
if counter_1 < 11:
filename = str(counter_1)
print str(line)
filename= str(count)
command ='curl ' + '"' + str(line).rstrip('\n') + '"'+ '> ./rawData/' + filename
output_1 = commands.getoutput(command)
input.close()
# PROCESSED DATA
counter_2 = 0
input = open('uri.txt','r')
t_2 = open('command','w')
for line in input:
counter_2 += 1
if counter_2 <11:
filename = str(counter_2) + '-processed'
command = 'lynx -dump -force_html ' + '"'+ str(line).rstrip('\n') + '"'+'> ./processedData/' + filename
print command
output_2 = commands.getoutput(command)
input.close()
我正在尝试用一个脚本来完成所有这些工作。谁能帮我完善我的代码以便我可以运行它?对于 .txt 文件中的每一行,它应该完全循环一次代码。例如,我的 .txt 文件中的每个 url 行都应该有 1 个原始和 1 个已处理的 .txt 文件。
【问题讨论】:
标签: python curl pycharm dump lynx