我試圖在標記中提取特定的字符串並保存它們(對於此行更復雜的處理)。所以說,例如,我在一條直線從一個文件中讀取當前行是:如何提取python中的特定字符串
<center><img border="0" src="http://www.world-of-waterfalls.com/images/Cascades_04_015L.jpg" WIDTH="500" HEIGHT="375" alt="Looking up the Merced River Canyon towards Bridalveil Fall from the Big Oak Flat Road" ***PINIT***></center><br clear="all"><br clear="all">
但我想存儲:
tempUrl = 'http://www.world-of-waterfalls.com/images/Cascades_04_015L.jpg'
tempWidth = 500
tempHeight = 375
tempAlt = 'Looking up the Merced River Canyon towards Bridalveil Fall from the Big Oak Flat Road'
我怎麼會去這樣做在Python ?
感謝
讓我爲你省去麻煩,並告訴你正則表達式出於此目的。不要以爲嘗試它,你以後只會碰到你的頭。如果數據來自Web源,請查看BeautifulSoup或scrapy或任何其他「抓取」庫。如果你已經有了標記,你可以使用解析器並遍歷節點並收集屬性信息。 –
['HTMLParser'](https://docs.python.org/2/library/htmlparser.html)或['html.parser'](https://docs.python.org/3.4/library/html。 parser.html)取決於python版本 –