我正在使用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)
Run Code Online (Sandbox Code Playgroud)
在我试图找到特定值的地方,我找到了一个模板,例如"{{formatPrice median}}"而不是"4.48".
我怎样才能使它能够检索值而不是占位符文本?
编辑:这是我正在尝试从中提取信息的特定页面.我正在尝试获取"中位数"值,该值使用模板{{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
Run Code Online (Sandbox Code Playgroud)
这是程序正在执行的屏幕截图.不幸的是,它似乎没有找到指定"formatPrice median"的任何内容.
我目前正在尝试使用Python 3.6中的请求和BeautifulSoup模块进行练习,并遇到了一个我似乎无法在其他问题和答案中找到任何信息的问题.
似乎在页面的某个时刻,Beuatiful Soup停止识别标签和ID.我试图从这样的页面中提取播放数据:
http://www.pro-football-reference.com/boxscores/201609080den.htm
import requests, bs4
source_url = 'http://www.pro-football-reference.com/boxscores/201609080den.htm'
res = requests.get(source_url)
if '404' in res.url:
raise Exception('No data found for this link: '+source_url)
soup = bs4.BeautifulSoup(res.text,'html.parser')
#this works
all_pbp = soup.findAll('div', {'id' : 'all_pbp'})
print(len(all_pbp))
#this doesn't
table = soup.findAll('table', {'id' : 'pbp'})
print(len(table))
Run Code Online (Sandbox Code Playgroud)
在Chrome中使用检查器,我可以看到该表肯定存在.我也尝试在HTML的后半部分使用'div'和'tr',它似乎不起作用.我已经尝试了标准的'html.parser'以及lxml和html5lib,但似乎没有任何效果.
我在这里做错了什么,或者HTML或其格式中是否存在阻止BeautifulSoup正确查找以后标签的内容?我遇到过这家公司(hockey-reference.com,basketball-reference.com)运营的类似网页的问题,但是能够在其他网站上正确使用这些工具.
如果它是HTML的东西,有没有更好的工具/库来帮助提取这些信息?
BF,谢谢你的帮助