【发布时间】:2017-10-01 14:04:28
【问题描述】:
我的一个学校项目有问题,说我应该用beautifulSoup 制作一个刮板程序,这将是一个令人惊喜的除草程序,并且会从他们给我的页面中打印出随机的5 个引号......我来了一个逻辑如何从网站上刮取数据并刮掉报价,但它不返回其中的 5 个,而是全部返回......
import urllib
from BeautifulSoup import BeautifulSoup
topic_url = 'http://quotes.yourdictionary.com/theme/marriage/'
topic_html = urllib.urlopen(topic_url).read()
topic_soup = BeautifulSoup(topic_html)
quotes = topic_soup.findAll('p', attrs={'class': 'quoteContent'})
for quote in quotes:
print quote.text + ("\n")
【问题讨论】:
标签: python python-2.7 web-scraping beautifulsoup