【发布时间】:2019-01-14 21:17:55
【问题描述】:
在过去的几个月里,我一直在学习 python 和 BeautifulSoup 函数,主要是为了我自己的研究目的而尝试使用网络抓取新闻文章。
但是,我在尝试将中文网站上的内容打印成文本时遇到了困难。
我应该使用哪个标签来获取文章的内容?
<<div class="w980 wbnav clear"><a
href="http://english.peopledaily.com.cn/"
target="_blank">English</a>>></div>
<div class="w980 wb_10 clear">
<h1>DPRK launches ballistic missile 'capable of hitting US
mainland'</h1>
<div> (<a
</div>
<div class="wb_12 clear">
<p style="text-align: center;">
<img alt="" src="/NMediaFile/2017/1129/FOREIGN201711291331000220555852915.jpg" style="width: 900px; height: 783px;" /></p>
<p>
The Democratic Peopleâs Republic of Korea (DPRK) has confirmed that it successfully tested a âHwasong 15â intercontinental ballistic missile (ICBM) on Wednesday.</p>
<p>
A Korean Central News Agency (KCNA) statement, which confirms earlier assessments from the United States and the Republic of Korea (ROK), claims the new type of ICBM "is capable of striking the whole mainland of the US."
</p>
<p>
It was Pyongyang's first test launch since a missile was fired in mid-September, days after its sixth-nuclear test.</p>
<p>
The ICBM was launched at 02:48 local time on Wednesday, according to the KCNA statement, and flew to an altitude of 4,475 km and then a distance of 950 km.</p>
<p>
It was launched from Sain Ni in the DPRK and flew for 53 minutes before splashing down into the Sea of Japan, said Pentagon spokesman Robert Manning.</p>
【问题讨论】:
-
内容没有明确的标签。按类获取div,然后获取它的
.text -
出于特定目的,您可能需要调查 Newspaper3k (github.com/codelucas/newspaper) 和 Goose Extractor (pypi.python.org/pypi/goose-extractor),它们似乎恰好专注于类似文章的数据。
标签: python beautifulsoup