我需要从网页上使用Python和BeautifulSoup从下面的代码中抓取文本'64%‘,请帮助。
<span class="textword" style="width:64%">BUY</span>向您致敬,巴斯多克
发布于 2017-07-03 03:27:07
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/44874334
复制相似问题