【发布时间】:2014-07-28 20:05:29
【问题描述】:
我正在开发一个解析 HTML 页面的项目。它适用于公司内部的网站,但我更改了示例,以便您尝试。
我获得了一个 HTML 页面的源代码并搜索了某个标记。然后我想提取这个标记的一个子字符串,但它不起作用。 Python 返回一个无...在我的代码下方,注释中包含 Python 的返回:
#!/usr/bin/python
import urllib2
from bs4 import BeautifulSoup
response = urllib2.urlopen("http://www.resto.be/restaurant/liege/4000-liege/8219-le-bar-a-gouts/")
page_source = response.read()
soup = BeautifulSoup(page_source)
name = soup.find_all("meta", attrs={"itemprop":"name"})
print(name[0])
# <meta content="LE BAR A GOUTS" itemprop="name"/>
print(name[0].find("<meta"))
# none
【问题讨论】:
-
在 Python 2 中,
print是一个语句,而不是一个函数。您可以在此处安全地删除(..)括号。
标签: python beautifulsoup urllib2