我正在使用Python 3,并试图从网站检索数据。然而,这个数据动态加载和我现在所拥有的代码不起作用:如何使用Python检索动态html内容的值
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位数}}“而不是”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 median”的东西。
当你访问浏览器中的URL时,你会得到模板标签吗?编辑:另外,你的模板如何呈现。如果您使用JavaScript模板引擎(例如Handlebars),这可能意味着您将在响应中获得模板标签。 –
RE编辑2 - 这只是一个新问题...无论如何,我认为你需要查看find_all的文档,因为你的find_all字符串无效。我将在下面更新一些更接近您需要的内容http://www.crummy.com/software/BeautifulSoup/bs3/documentation.html#arg-name。 –
干杯!我尝试使用soup.findall(True)来获取所有标签,并且我需要的信息就在那里!这只是为了找到我需要搜索哪个标签以获取该信息。 – Tagc