【发布时间】:2016-10-24 14:39:03
【问题描述】:
我正在尝试从电视节目中抓取一些脚本。我可以使用 BeautifulSoup 和 Requests 获取所需的文本。
import requests
from bs4 import BeautifulSoup
r = requests.get('http://www.example.com')
s = BeautifulSoup(r.text, 'html.parser')
for p in s.find_all('p'):
print p.text
到目前为止效果很好。但我只想要某个角色的那些段落。说他的名字是“stackoverflow”。文本将是这样的:
答:sdasd sd asda B:sdasds 堆栈溢出:帮助?
所以我只想要 STACKOVERFLOW 所说的内容。不是其余的。
我试过了
s.find_all(text='STACKOVERFLOW') but I get nothing.
这样做的正确方法是什么?一个正确方向的提示将不胜感激。
【问题讨论】:
标签: python python-2.7 web-scraping beautifulsoup