2012-01-23 35 views

回答

2

有點去錯了。其原因錯在於您使用編號索引來查找您想要的標籤 - BeautifulSoup會根據標籤或屬性使標籤更加簡單。

你想要的東西像

tempSite = preSite+'/contact_us/' 
print tempSite 
theTempSite = urlopen(tempSite).read() 
soup = BeautifulSoup(theTempSite) 
tag = soup.find("input", { "name" : "bb_recipient" }) 
print tag['value'] 
+0

標記和歸因幫助很大,但我仍然不是很讓我在尋找的輸出:在這種情況下,它現在印刷[] - 我想顯式拼接值字段作爲唯一的輸出。 – Hikalea

+0

Urp ..檢查更新.. – synthesizerpatel

+0

'.findAll()'返回一個列表。使用'soup.find('input',dict(name =「bb_recipient」,value = True))'獲取第一個找到的元素。 – jfs

0

如果問題是如何從標籤對象屬性的值,那麼你可以使用它作爲一個字典:

lightwaveEmail['value'] 

您可以找到有關此內容的BeautifulSoup documentation的更多信息。

如果問題是如何在湯中找到所有input標籤這樣的值,那麼你可以找他們如下:

soup.findAll('input', value=re.compile(r'[email protected]')) 

你也可以找到在BeautifulSoup documentation一個類似的例子。

相關問題