【发布时间】:2013-07-09 23:07:50
【问题描述】:
我正在使用 Python 3,并且正在尝试从网站检索数据。但是,这些数据是动态加载的,我现在的代码不起作用:
url = eveCentralBaseURL + str(mineral)
print("URL : %s" % url);
response = request.urlopen(url)
data = str(response.read(10000))
data = data.replace("\\n", "\n")
print(data)
在我试图找到一个特定值的地方,我找到了一个模板,例如“{{formatPrice median}}”而不是“4.48”。
我怎样才能使我可以检索值而不是占位符文本?
编辑:This 是我试图从中提取信息的特定页面。我正在尝试获取使用模板 {{formatPrice median}}
的“中值”值编辑 2:我已经安装并设置了我的程序以使用 Selenium 和 BeautifulSoup。
我现在的代码是:
from bs4 import BeautifulSoup
from selenium import webdriver
#...
driver = webdriver.Firefox()
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html)
print "Finding..."
for tag in soup.find_all('formatPrice median'):
print tag.text
Here 是程序执行时的屏幕截图。不幸的是,它似乎没有找到任何指定“formatPrice 中位数”的东西。
【问题讨论】:
-
在浏览器中访问网址时,是否得到模板标签?编辑:另外,您的模板是如何呈现的。如果您使用的是 javascript 模板引擎(例如 Handlebars),这可能意味着您将在响应中获得模板标签。
-
RE 编辑 2 - 这只是一个新问题......无论如何,我认为您需要查看 find_all 的文档,因为您的 find_all 字符串无效。我将在下面更新一些更接近您需要的内容crummy.com/software/BeautifulSoup/bs3/…。
-
干杯!我尝试使用soup.findall(True) 来获取所有标签,而我需要的信息就在那里!只需准确找到我需要搜索哪个标签来获取该信息。
标签: python html templates urllib