-3
我的問題是解析一個網站,然後加載數據樹與BS。我如何查找<em>
標籤的內容?我試過Python BeautifulSoup無法選擇特定的標記
for first in soup.find_all("li", class_="li-in"):
print first.select("em.fl.in-date").string
#or
print first.select("em.fl.in-date").contents
但它不工作。請幫助。
我對tutti.ch
尋找汽車這裏是我的全部代碼:
#Crawl tutti.ch
import urllib
thisurl = "http://www.tutti.ch/stgallen/fahrzeuge/autos"
handle = urllib.urlopen(thisurl)
html_gunk = handle.read()
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_gunk, 'html.parser')
for first in soup.find_all("li", class_="li-in"):
if first.a.string and "Audi" and "BMW" in first.a.string:
print "Geschafft: %s" % first.a.contents
print first.select("em.fl.in-date").string
else:
print first.a.contents
當它找到一個寶馬或者奧迪應該檢查插入車內時。時間位於這樣的EM-標籤:
<em class="fl in-date"> Heute <br></br> 13:59 </em>
太謝謝你了亞當·巴恩斯。你的代碼完美無缺! –
'和「奧迪」總是會是真的 –