【发布时间】:2018-03-15 20:07:39
【问题描述】:
我正在尝试使用 Beautiful Soup 从 rottentomatoes.com 上抓取电影台词。页面来源很有趣,因为引号直接由跨度类“bold quote_actor”进行,但报价本身位于没有类的跨度中,例如(https://www.rottentomatoes.com/m/happy_gilmore/quotes/): screenshot of web source
我想使用 Beautiful Soup 的 find_all 来捕获所有引用,而不是演员的名字。我尝试了很多事情都没有成功,例如:
moviequotes = soup(input)
for t in web_soup.findAll('span', {'class':'bold quote_actor'}):
for item in t.parent.next_siblings:
if isinstance(item, Tag):
if 'class' in item.attrs and 'name' in item.attrs['class']:
break
print (item)
我将非常感谢有关如何浏览此代码并将生成的纯文本引号定义到我与 Pandas 等一起使用的对象中的任何提示。
【问题讨论】:
标签: python web-scraping beautifulsoup