0
我需要從網頁上的下面的代碼使用Python和BeautifulSoup刮'文本'64%',請幫助。Python BeautifulSoup StyleTag提取
<span class="textword" style="width:64%">BUY</span>
問候,babsdoc
我需要從網頁上的下面的代碼使用Python和BeautifulSoup刮'文本'64%',請幫助。Python BeautifulSoup StyleTag提取
<span class="textword" style="width:64%">BUY</span>
問候,babsdoc
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)
重複https://stackoverflow.com/questions/37843903/getting-style-of-tr-tag-using-beautifulsoup – TrakJohnson
致謝!從您發佈TrakJohnson的帖子中得到答案! – babsdoc
沒問題,在將來請求任何內容之前,請儘量[谷歌搜索的最低限度](https://www.google.fr/search?q=get+style+beautifulsoup) – TrakJohnson