Python 3.x 通过HTML解析以使用beautiful soup从表行中提取数据

Python 3.x 通过HTML解析以使用beautiful soup从表行中提取数据,python-3.x,web-scraping,beautifulsoup,Python 3.x,Web Scraping,Beautifulsoup,我正在使用BeautifulSoup从纳斯达克网站上提取股票信息。我想专门从HTML页面上的表行中检索信息,但总是出现错误(第12行) 您可以这样做来从表行中获取数据 import requests from bs4 import BeautifulSoup import re r = requests.get("https://www.nasdaq.com/") print(r) soup = BeautifulSoup(r.content, 'html.parser') data = s

我正在使用BeautifulSoup从纳斯达克网站上提取股票信息。我想专门从HTML页面上的表行中检索信息,但总是出现错误(第12行)


您可以这样做来从表行中获取数据

import requests
from bs4 import BeautifulSoup
import re

r = requests.get("https://www.nasdaq.com/")

print(r)
soup = BeautifulSoup(r.content, 'html.parser')
data = soup.find('table',{'id':'indexTable', 'class':'floatL marginB5px'}).script.text
matches = re.findall(r'nasdaqHomeIndexChart.storeIndexInfo(.*);\r\n', data)
table_rows = [re.findall(r'\".*\"', row) for row in matches]
print(table_rows)

table\u rows
是包含表数据的列表。

能否添加预期输出?请告诉我们有关该特定表的更多信息。它在哪里
import requests
from bs4 import BeautifulSoup
import re

r = requests.get("https://www.nasdaq.com/")

print(r)
soup = BeautifulSoup(r.content, 'html.parser')
data = soup.find('table',{'id':'indexTable', 'class':'floatL marginB5px'}).script.text
matches = re.findall(r'nasdaqHomeIndexChart.storeIndexInfo(.*);\r\n', data)
table_rows = [re.findall(r'\".*\"', row) for row in matches]
print(table_rows)