PythonでBeautifulSoupを利用してNYTのタイトルを取ってみる
PythonでBeautifulSoupを利用してNYTのタイトルを取ってみます。
>>> import nltk >>> from urllib import urlopen >>> url="http://topics.nytimes.com/top/news/international/countriesandterritories/japan/index.html" >>> html = urlopen(url).read() >>> from BeautifulSoup import BeautifulSoup >>> soup = BeautifulSoup(html) >>> soup.find('title',) <title>Japan News - Earthquake, Tsunami and Nuclear Crisis (2011) </title> >>>
なでしこジャパンの記事でも同様にタイトルを取ってみます。
>>> url2="http://www.nytimes.com/2011/07/15/sports/soccer/japans-world-cup-team- lifts-a-country.html" >>> html = urlopen(url2).read() >>> soup = BeautifulSoup(html) >>> soup.find('title',) <title>Japan's World Cup Team Lifts a Country - NYTimes.com</title> >>>