我需要替换远程XML文件中的一些单词。
我设法改变了HD' HD'使用第一行,但其余的行似乎被跳过了' if语句'。
for item in items:
try:
name = item('title')[0].string
name = name.replace('HD', 'HDD')
name = name.replace('aa help', 'aa hel')
name = name.replace('zs a help', 'zs a help g')
if name is None:
name = 'unknown?'
except:
addon_log('Name Error')
name = ''
我哪里错了?
编辑:
按要求提供源XML。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<items>
<items_info>
<title>Main Server</title>
<genre>Sport</genre>
<description>Main Server Listings</description>
<thumbnail>http://173.com/wp/fan.jpg</thumbnail>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<date>August 30, 2015</date>
<credits>meio</credits>
</items_info>
<item>
<title>test HD</title>
<link>http://173.com/ne/plad69/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>test ch1 hdd</channel>
<epgdata>catch up</epgdata>
</item>
<item>
<title>aa help</title>
<link>http://173.com/ne/plad60/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>aahe</channel>
<epgdata>catch up</epgdata>
</item>
<item>
<title>zs a help</title>
<link>http://173.com/ne/plad64/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>zsahe</channel>
<epgdata></epgdata>
</item>
<item>
<title>gfg HD</title>
<link>http://173.com/ne/plad46/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>ghd</channel>
<epgdata></epgdata>
</item>
<item>
<title>aa help hd</title>
<link>http://173.com/ne/plad26/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>aahehd</channel>
<epgdata>catch up</epgdata>
</item>
<item>
<title>1234</title>
<link>http://173.com/ne/plad61/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>334</channel>
<epgdata></epgdata>
</item>
<item>
<title>test 3443 hd</title>
<link>http://173.com/ne/plad67/playlist.mp4</link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>boo</channel>
<epgdata>catch up</epgdata>
</item>
<item>
<title>zs a help hd</title>
<link>http://173.com/ne/plad76/playlist.mp4/link>
<fanart>http://173.com/wp/fan1.jpg</fanart>
<genre>Sport</genre>
<channel>zshelhd1</channel>
<epgdata></epgdata>
</item>
</items>
</xml>