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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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将HTML表格导出到excel而不刷新页面_Python_Django_Pandas_Html Table_Export To Excel - Fatal编程技术网

使用python将HTML表格导出到excel而不刷新页面

使用python将HTML表格导出到excel而不刷新页面,python,django,pandas,html-table,export-to-excel,Python,Django,Pandas,Html Table,Export To Excel,我有一个网页,用户可以在其中生成一个表,其中包含行数和列数输入 现在我想使用python将这个HTML表导出到excel文件中。通过谷歌搜索,我了解了如下所示的to_excel代码片段 import pandas as pd # The webpage URL whose table we want to extract url = "https://www.geeksforgeeks.org/extended-operators-in-relational-algebra/" # As

我有一个网页,用户可以在其中生成一个表,其中包含行数列数输入

现在我想使用python将这个HTML表导出到excel文件中。通过谷歌搜索,我了解了如下所示的to_excel代码片段

import pandas as pd 

# The webpage URL whose table we want to extract 
url = "https://www.geeksforgeeks.org/extended-operators-in-relational-algebra/"

# Assign the table data to a Pandas dataframe 
table = pd.read_html(url)[0] 

# Store the dataframe in Excel file 
table.to_excel("data.xlsx") 
从上面的代码可以看出,程序导航到指定的url,但在我的网页中,如果点击url,所有数据都会消失(页面刷新后),因为我在不刷新页面的情况下生成了大量的行和列


有人可以建议使用python导出HTML表格的excel替代方法吗?

不要传递url,传递包含HTML的原始字符串:

参数:

io:(str、路径对象或类似文件的对象)

URL、类似文件的对象或包含HTML的原始字符串。注意 lxml只接受http、ftp和文件url协议。如果你有 以“https”开头的URL您可以尝试删除“s”