我使用這個代碼,以查找頁面中所有相關鏈接:BeautifulSoup - 簡單的方法來獲得免費的HTML內容
soup.findAll('a', href=re.compile('^notizia.php\?idn=\d+'))
而且它的工作非常好。不幸的是,在一個標籤有很多嵌套標籤,如字體,b和不同的東西...我想只得到文本內容,沒有任何其他的HTML標籤。鏈接
例子:
<A HREF="notizia.php?idn=1134" OnMouseOver="verde();" OnMouseOut="blu();"><FONT CLASS="v12"><B>03-11-2009: <font color=green>CCS Ingegneria Elettronica-Sportello studenti ed orientamento</B></FONT></A>
當然它的醜陋(和標記並不總是一樣的!),我想獲得:
03-11-2009: CCS Ingegneria Elettronica-Sportello studenti ed orientamento
在本文檔中,它說在findAll方法中使用text=True
,但它會忽略我的正則表達式。爲什麼?我該如何解決這個問題?
PyQuery聽起來像一個非常酷的替代方案:http://pypi.python.org/pypi/pyquery – 2009-11-17 23:41:53