2017-07-02 15 views
0

PythonとBeautifulSoupを使用して、Webページの下のコードから'64% 'というテキストをスクラップする必要があります。Python BeautifulSoup StyleTag Extract

<span class="textword" style="width:64%">BUY</span> 

よろしく、babsdoc

+1

https://stackoverflow.com/questions/37843903/getting-style-of-tr-tag-using-beautifulsoup – TrakJohnson

+0

感謝の重複!あなたがTrakJohnsonを投稿したスレッドからの答えを得ました! – babsdoc

+0

今後も問題がないので、何かを尋ねる前に[最小限の検索を実行してください](https://www.google.fr/search?q=get+style+beautifulsoup) – TrakJohnson

答えて

0
from bs4 import BeautifulSoup 
html='<span class="textword" style="width:64%">BUY</span>' 
soup=BeautifulSoup(html,'lxml') 

#if you have only one such element: 
needed_text = soup.find('span', {'style':'width:64%'}).text 

#if you have many elements to scrape: 
needed_text = [] 
needed_text_tags = soup.find_all('span', {'style':'width:64%'}) 
for i in needed_text_tags: 
    needed_text.append(i.text)