2012-01-23 13 views
1

こするためにソースコードを解析するbeautfiulsoup使用:Pythonの正規表現文字列の除外

tempSite = preSite+'/contact_us/' 
print tempSite 
theTempSite = urlopen(tempSite).read() 
currentTempSite = BeautifulSoup(theTempSite) 
lightwaveEmail = currentTempSite('input')[7] 

#<input type="Hidden" name="bb_recipient" value="[email protected]" /> 
のみ [email protected]が印刷されるように

どのように私はlightwaveEmailをre.compileことができますか?

答えて

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

タグ付けと帰属のようなものは、しかし、私はまだかなり私が探しているの出力が届かない、途方もなく助けたいですname = "bb_recipient" value = "[email protected]" />] - 値フィールドを明示的に唯一の出力としてスプライスする必要があります。 – Hikalea

+0

Urp .. check update .. – 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でも同様の例を見つけることができます。

関連する問題