Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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 3.x BeautifulSoup查找所有表为空_Python 3.x_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 3.x BeautifulSoup查找所有表为空

Python 3.x BeautifulSoup查找所有表为空,python-3.x,web-scraping,beautifulsoup,Python 3.x,Web Scraping,Beautifulsoup,我试图从NOAA网站上抓取一张非常简单的表格: 该表是一个“.dat”文件,该站点似乎是html格式的。当我使用BeautifulSoup阅读内容时,我可以很好地看到内容。然而,当我搜索带有“find_all”或“find”的表时,我什么也没有得到,即[] 这是我的初始代码: page = requests.get('https://www1.ncdc.noaa.gov/pub/data/cdo/samples/PRECIP_HLY_sample_ascii.dat') soup = Beaut

我试图从NOAA网站上抓取一张非常简单的表格:

该表是一个“.dat”文件,该站点似乎是html格式的。当我使用BeautifulSoup阅读内容时,我可以很好地看到内容。然而,当我搜索带有“find_all”或“find”的表时,我什么也没有得到,即[]

这是我的初始代码:

page = requests.get('https://www1.ncdc.noaa.gov/pub/data/cdo/samples/PRECIP_HLY_sample_ascii.dat')
soup = BeautifulSoup(page.content,'html.parser') #'html5lib' #'html.parser' 'lxml'
table = soup.find_all('table')     
当我输入soup时,我会得到以下信息:

然而,当我试图将信息放入表中时,结果却是空白的

table
>> []
我尝试了以下变化:

page = urllib.request.urlopen('https://www1.ncdc.noaa.gov/pub/data/cdo/samples/PRECIP_HLY_sample_ascii.dat').read()

soup = BeautifulSoup(page,'lxml')
soup = BeautifulSoup(page,'html5lib') #'' #''

table = soup.findAll('table') 
table = soup.findAll("div",{"class":"line-gutter-backdrop"}) 
table = soup.find_all(True)
然而,这张表还是一片空白

我发现这个问题似乎很相似:

但我的表不是javascript(据我所知)。它只是文本


我对数据抓取非常陌生,真的不知道为什么这个简单的例子不起作用。非常感谢您的帮助。多谢各位

您无法找到
标记,因为没有,您必须找到
pre
标记

您可以尝试此代码段,它将获取表中的文本:

from bs4 import BeautifulSoup as soup
import urllib

url = 'https://www1.ncdc.noaa.gov/pub/data/cdo/samples/PRECIP_HLY_sample_ascii.dat'

response = urllib.request.urlopen(url)
html = response.read()

page_soup = soup(html,'lxml')
table = page_soup.find('p')
print(table.text)
输出:

STATION           STATION_NAME                                       ELEVATION  LATITUDE   LONGITUDE  DATE           HPCP     Measurement Flag Quality Flag 
----------------- -------------------------------------------------- ---------- ---------- ---------- -------------- -------- ---------------- ------------ 
COOP:310301       ASHEVILLE NC US                                    682.1      35.5954    -82.5568   20100101 00:00    99999                ]              
COOP:310301       ASHEVILLE NC US                                    682.1      35.5954    -82.5568   20100101 01:00        0                g              
COOP:310301       ASHEVILLE NC US                                    682.1      35.5954    -82.5568   20100102 06:00        1     

非常感谢。有没有一种方法可以使用这种方法将其放入pandas数据框中?我认为pandas用于从表标记获取数据,所以我认为这在这里是不可能的。但我不是熊猫专家:-)昨天这个问题还有另一个答案,但现在它不见了。请转寄好吗?非常感谢。