我如何使用 python 2.7 中的 BeautifulSoup4 从该特定网站提取 "date"?
How do i extract "date" from this specific website using BeautifulSoup4 in python 2.7?
我要提取
DATE not data
从下面给出的 link:
http://www.thehindu.com/sci-tech/science/iit-bombay-birds-eye-view-and-quantum-biology/article18191268.ece
在 python 中使用 BeautifulSoup4 2.7.I 希望输出如下所示:
April 22, 2017 18:57 IST
这是我的解决方案。
import urllib2
from bs4 import BeautifulSoup
response = urllib2.urlopen('http://www.thehindu.com/sci-tech/science/iit-bombay-birds-eye-view-and-quantum-biology/article18191268.ece'
)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
ut_container = soup.find("div", {"class": "ut-container"})
time = ut_container.find("none").text.strip()
print(time)
但是 IMO 你必须做好准备 - 在使用 bs4 时 - 玩它,寻找 html 选择器,搜索文档,并保持耐心。
希望这不是你的懒惰 ;)
我要提取
DATE not data
从下面给出的 link:
http://www.thehindu.com/sci-tech/science/iit-bombay-birds-eye-view-and-quantum-biology/article18191268.ece
在 python 中使用 BeautifulSoup4 2.7.I 希望输出如下所示:
April 22, 2017 18:57 IST
这是我的解决方案。
import urllib2
from bs4 import BeautifulSoup
response = urllib2.urlopen('http://www.thehindu.com/sci-tech/science/iit-bombay-birds-eye-view-and-quantum-biology/article18191268.ece'
)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
ut_container = soup.find("div", {"class": "ut-container"})
time = ut_container.find("none").text.strip()
print(time)
但是 IMO 你必须做好准备 - 在使用 bs4 时 - 玩它,寻找 html 选择器,搜索文档,并保持耐心。
希望这不是你的懒惰 ;)