使用Python上的Web爬虫打印文章

使用Python上的Web爬虫打印文章,python,web-scraping,web-crawler,Python,Web Scraping,Web Crawler,我是Python新手,我正在尝试制作一个只打印文章(例如本网站-)而不打印网站上其他内容的网络爬虫。我试过这个(但不起作用): 还有它的印刷品:“没有” thx您只需要这篇文章,而不是循环: for link in soup.findAll('div', {'class': 'article-entry text'}): title = link.string print(title) 让它: title = soup.find('h1', {'class': 'alpha tweet

我是Python新手,我正在尝试制作一个只打印文章(例如本网站-)而不打印网站上其他内容的网络爬虫。我试过这个(但不起作用):

还有它的印刷品:“没有”
thx

您只需要这篇文章,而不是
循环:

for link in soup.findAll('div', {'class': 'article-entry text'}):
  title = link.string
  print(title)
让它:

title = soup.find('h1', {'class': 'alpha tweet-title'}).get_text()
article = soup.find('div', {'class': 'article-entry text'}.get_text()
print title
print article
你只能得到标题和文章


关于这方面的文档可能会有所帮助。

Thx它正在工作。但是它的左、右和不同的线条上都印有。有没有办法不用就得到它,或者用相同的字符串得到它?
title = soup.find('h1', {'class': 'alpha tweet-title'}).get_text()
article = soup.find('div', {'class': 'article-entry text'}.get_text()
print title
print article