def scrape(url):
### opens url so it's like a file
try:
link = urllib.request.urlopen(url)
except urllib.error.HTTPError:
return ''
soup = BeautifulSoup(link.read().decode('utf-8'), 'lxml', parse_only=SoupStrainer('p'))
alltxt = ''
### iterate thru the <p> tags
for para in soup.find_all('p'):
alltxt = alltxt + para.get_text() + ' '
return alltxt
评论列表
文章目录