Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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 Beautifulsoup/API中刮表_Python_Api_Web Scraping_Beautifulsoup - Fatal编程技术网

如何从Python Beautifulsoup/API中刮表

如何从Python Beautifulsoup/API中刮表,python,api,web-scraping,beautifulsoup,Python,Api,Web Scraping,Beautifulsoup,我正试图把桌子从桌子上刮下来 我使用了类似于下面的代码,但不起作用 source = urllib.request.urlopen('https://www.cnbc.com/sector-etfs/').read() soup = bs.BeautifulSoup(source,'lxml') table = soup.find_all('table') pd.read_html(str(table))[0] 我还尝试了requests.get函数来获取数据,但无法转换为表格式。你能帮我把数

我正试图把桌子从桌子上刮下来

我使用了类似于下面的代码,但不起作用

source = urllib.request.urlopen('https://www.cnbc.com/sector-etfs/').read()
soup = bs.BeautifulSoup(source,'lxml')
table = soup.find_all('table')
pd.read_html(str(table))[0]

我还尝试了requests.get函数来获取数据,但无法转换为表格式。你能帮我把数据整理成表格格式吗?非常感谢。

页面源代码中没有表格。数据来自XHR。请尝试以下方式获取数据:

import requests

url = 'https://quote.cnbc.com/quote-html-webservice/quote.htm?noform=1&partnerId=2&fund=1&exthrs=0&output=json&symbolType=issue&symbols=289752|289759|289840|289776|136746|289783|289847|289856|289812|289745|5064448|171658|4114925|4733797|281752|21583731|171610|42634418|5064445|5064446|42634422|151687|3585851|5064447|29549437&requestMethod=extended'
data = requests.get(url).json()
print(data)

谢谢你的回复。正如我提到的,我已经试过这种方法了。。是否有一种方法可以获取数据帧格式的数据?@Steve.Kim,数据以JSON的形式提供。不像数据帧格式。您需要将其转换为您喜欢的格式,就像web客户端上的JavaScript一样。由于您的问题听起来不像“如何将JSON转换为HTML表”,请尝试为此问题创建新问题