首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python BeautifulSoup StyleTag Extract

Python BeautifulSoup StyleTag Extract
EN

Stack Overflow用户
提问于 2017-07-03 03:14:25
回答 1查看 139关注 0票数 0

我需要从网页上使用Python和BeautifulSoup从下面的代码中抓取文本'64%‘,请帮助。

代码语言:javascript
复制
<span class="textword" style="width:64%">BUY</span>

向您致敬,巴斯多克

EN

回答 1

Stack Overflow用户

发布于 2017-07-03 03:27:07

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44874334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档