2016-05-06 14 views
-1

コードに記載されているUR1から価格を取得しようとしています。BeautifulSoupの要素からテキスト値を取得します

import requests 
from bs4 import BeautifulSoup 

r = requests.get("http://www.forever21.com/IN/Product/Product.aspx? 
BR=LOVE21&Category=whatsnew_app&ProductID=2000054242&VariantID=") 
soup = BeautifulSoup(r.content, 'html.parser') 
#print(soup.prettify()) 
price = soup.find_all("font",{"class":"items_price"}) 
print(price) 

#Output: 
<font class="items_price">Rs.1,249</font> 

私は誰かが何をすべきかと言うことができますRs.1,249 ある価格だけを必要としますか? は

+0

。:はAttributeError:text' –

答えて

1

ResultSetがリストであるありがとう。

あなただけの `soup.find( "フォント"、{ "クラス": "items_price"})必要
print (price[0].get_text()) 
+0

それは今働いています:)ありがとう皆さん –

+1

あなたが回答を受け入れる場合は、それを合格とマークする必要があります。ケシャフ。 – durdenk

0

は、単にユーザー.get_text()

>>> price = soup.find("font",{"class":"items_price"}) 
>>> print(price.get_text()) 
'Rs.1,249' 
+0

が試したが、エラーました 'のResultSet' オブジェクトが属性を持っていない 'をGET_TEXT' –

+0

@KeshavReddy - 'find_all'を使用したので、これは複数の要素を返します。したがって、' ResultSet'を返します。あなたは 'price [0] .get_text()'を使うこともできますし、単に '' find''(https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find)素子。 – JRodDynamite

関連する問題