Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python BeautifulSoup4:缺少已解析的表数据_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python BeautifulSoup4:缺少已解析的表数据

Python BeautifulSoup4:缺少已解析的表数据,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我试图通过BeautifulSoup 4从中提取每股收益数据 当我解析数据时,使用默认的,lxml和HTML5解析器缺少表信息。我相信这与Javascript有关,我一直在尝试实现PyV8,以便将脚本转换为BS4的可读HTML。问题是我不知道该怎么办 你知道这是不是我的问题吗?我已经读了很多帖子,今天这对我来说是一个很大的头痛。下面是一个简单的例子。financeWrap包含表信息,但beautifulSoup显示为空 import requests from bs4 import Beauti

我试图通过BeautifulSoup 4从中提取每股收益数据

当我解析数据时,使用默认的,
lxml
和HTML5解析器缺少表信息。我相信这与Javascript有关,我一直在尝试实现
PyV8
,以便将脚本转换为BS4的可读HTML。问题是我不知道该怎么办

你知道这是不是我的问题吗?我已经读了很多帖子,今天这对我来说是一个很大的头痛。下面是一个简单的例子。
financeWrap
包含表信息,但beautifulSoup显示为空

import requests
from bs4 import BeautifulSoup

url = "http://financials.morningstar.com/ratios/r.html?t=AAPL&region=usa&culture=en-US"

response = requests.get(url)
soup_key_ratios = bs(response.content, 'html5lib')
financial_tables = soup_key_ratios.find("div", {"id":"financeWrap"})
print financial_tables

# Output: <div id="financeWrap">
#           </div>
导入请求
从bs4导入BeautifulSoup
url=”http://financials.morningstar.com/ratios/r.html?t=AAPL®ion=usa&culture=en-美国“
response=requests.get(url)
soup\u key\u ratio=bs(response.content,'html5lib')
financial_tables=soup_key_ratio.find(“div”,{“id”:“financeWrap”})
打印财务报表
#输出:
#           

问题在于,您试图获取通过Ajax在网站上输入的数据。如果您转到提供的链接,并通过浏览器查看源代码,您将看到数据中不应有任何内容

但是,如果您使用控制台管理器,例如,您将看到有对以下内容的Ajax请求,这是您可以通过beautifulsoup解析的内容(也许-我还没有尝试过或查看过数据结构)


请记住,这很可能违反了网站的ToS。

@Begueradj这是一个有趣的观察。我发现,通常只要你仔细看,你就能找到答案@BryceDoganer用
beautifulsoup
标记您的问题。这将帮助您快速得到一个好的答案。也许我遗漏了什么,但有什么原因可以解释为什么
http://...en-US
不是作为字符串引用吗?@alexwlchan在我的代码中,它是在引号中,我忘了在这里添加它。已编辑使用chrome访问:
查看源代码:http://financials.morningstar.com/ratios/r.html?t=AAPL®ion=usa&culture=en-在美国
,你会发现bs4并没有什么错!这就是我想说的。@Duniyadnd谢谢你指出这一点。我想它一定是与这些线索相关的,我只是不知道如何找到请求链接。我将调查Firebug,并了解ToS。