[英]How to read a file and write it entirely to several text files using Python?
[英]Read several files and write line n of each file to another file using python
我在文件中有几个链接。 我想遍历每个链接的网页(源),从该页面获取第443行(包含如下所示的特定详细信息),并将其与相应的链接一起写入另一个文件。
输入文件:
http:// abc / app / application_144733409001
http:// abc / app / application_144733409001
http:// abc / app / application_144733409000
http:// abc / app / application_144733409003
http:// abc / app / application_144733409005
http:// abc / app / application_144733409008
http:// abc / app / application_144733409009
http:// abc / app / application_144733409006
预期输出文件:
http:// abc / app / application_144733409001 31098 MB-秒,3 vcore-秒
http:// abc / app / application_144733409001 31098 MB-秒,2 vcore-秒
http:// abc / app / application_144733409000 31098 MB-秒,3 vcore-秒
http:// abc / app / application_144733409003 31098 MB-秒,5 vcore-秒
http:// abc / app / application_144733409005 31798 MB-秒,7 vcore-秒
http:// abc / app / application_144733409008 31018 MB-秒,3 vcore-秒
http:// abc / app / application_144733409009 31097 MB-秒,3 vcore-秒
http:// abc / app / application_144733409006 31094 MB-秒,3 vcore-秒
码:
import sys
import urllib
Lines = [Line.strip() for Line in open ('input.txt','r').readlines()]
with open('/home/try/intermediate.txt', 'w') as out_file:
for Line in Lines:
page = urllib.urlopen(line).read()
#print page
我不知道该如何进行。 请帮助我。 提前致谢
使用re
检查行以找到匹配的字符串https://regex101.com/r/nU3xW1/1
for line in Lines:
remoteLine = urllib.urlopen(line)
for l in remoteLine:
matchObj = re.match(r'(\d+) MB-seconds, (\d+) vcore-seconds', l)
if matchObj:
print "matchObj.group() : ", matchObj.group()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.