以下のテキストファイルを読み込んでいますformat(a.txt)
。
http://www.example.com/forum/showthread.php?t=779689/images/webcard.jpg 121.10.208.31
www.example.com
次に、の部分だけを取得/images/webcard.jpg 121.10.208.31
して、同じファイルまたは別のファイルに書き込む必要があります。この場合、私はそれをに書いていb.txt
ます。
from urlparse import urlparse
f = open('a.txt','r')
fo = open('b','w')
for line in f:
fo.write(urlparse(line).netloc+ ' ' + line.split(' ')[1] + ' ' + line.split(' ')[2] + '\n')
上記のコードは次のエラーを出しますか?これを達成する方法は?
Traceback (most recent call last):
File "prittyprint.py", line 17, in <module>
fo.write(urlparse(line).netloc+ ' ' + line.split(' ')[1] + ' ' + line.split(' ')[2] + '\n')
IndexError: list index out of range