Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.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 刮表数据_Python_Dataframe_Web Scraping_Html Table_Scrapy - Fatal编程技术网

Python 刮表数据

Python 刮表数据,python,dataframe,web-scraping,html-table,scrapy,Python,Dataframe,Web Scraping,Html Table,Scrapy,我是一个编程初学者,现在我开始使用Python和Scrapy,这是我的第一个代码 针对以下问题运行:我正在抓取的表不是在带有标题/索引的列中格式化的,而是在一个字符串中格式化的,因为每个页面都有可变数量的列和行,因此很难在.CSV或JSON中拆分所有内容,因为属性将混合在一起 示例: 栏目: 代码 类型 压力(Pa) 消耗量(Nm3/h) 输出(W) 重量(克) 栏目: 代码 数字 类型 d1(毫米) d2(毫米) h(毫米) 包装(pc) 我如何调整我的代码,使所有可变表格标题都将被计数并放

我是一个编程初学者,现在我开始使用Python和Scrapy,这是我的第一个代码

针对以下问题运行:我正在抓取的表不是在带有标题/索引的列中格式化的,而是在一个字符串中格式化的,因为每个页面都有可变数量的列和行,因此很难在.CSV或JSON中拆分所有内容,因为属性将混合在一起

示例:

栏目:

代码
类型
压力(Pa)
消耗量(Nm3/h)
输出(W)
重量(克)

栏目:

代码
数字
类型
d1(毫米)
d2(毫米)
h(毫米)
包装(pc)


我如何调整我的代码,使所有可变表格标题都将被计数并放入列+它们的数据中。

我假设您正试图从网站中刮取表格数据,在这种情况下,use可以使用以下代码。它将很容易为你做这项工作

import requests
import pandas as pd
url = 'https://www.kavalier.cz/en/desiccator-with-glass-knob-sp94.html'
html = requests.get(url).content
df_list = pd.read_html(html)
df = df_list[-1]
print(df)

如何将其与脚本相结合,或者如何在脚本中添加分页提示?我还需要删除以下内容:“'Product_Name':response.css('.content>h2::text')。extract_first(),'Category':response.css('.breadcrumb>li:nth child(4)>a::text')。extract_first(),'Image_Url':response.css('.main img>a::attr(href')。extract_first(),'
import requests
import pandas as pd
url = 'https://www.kavalier.cz/en/desiccator-with-glass-knob-sp94.html'
html = requests.get(url).content
df_list = pd.read_html(html)
df = df_list[-1]
print(df)