你好,我尝试在每次运行 python 代码时自动使用 python 修改汇合表(追加新行)。我能够连接到 Confluence API 并获取 Confluence 页面的正文并找到目标表。然后,当我将 JSON 文本转换为数据帧以添加新数据(行)时,我找到了表格,后台也进行了计算。然后我将该数据框表保存回 html,这就是我在用新的 html 表替换旧的 html 表时遇到问题的地方。
# This is JSON payload from confluence API
response_text_json = json.loads(response_text)
This is the value of the contents of the confluence API
table_value = response_text_json['body']['storage']['value']
soup = bs.BeautifulSoup(table_value, "html.parser")
tables = soup.find_all("table") # should only contain 3 tables
# this is the table I am replacing with table (appended row)
df_main = pd.read_html(str(tables))[2]
# Data Manipulations sections #
df_main.loc[len(df_main)] = ['Data', 'Data', 'Data']
str_df_main = df_main.to_html(index=False)
tables[2].string = str_df_main
soup = str(soup)
## injecting it back to confluence using PUT
我能够找到修改和附加新数据所需的表,并将其转换回 html,但是当我更新 confluence 页面时,它返回新数据表的实际 HTML 字符串,而不是表。
你能帮我解决我做错了什么吗?抱歉,我是处理 HTML 标签的新人
我找到了错误的原因了!
tables[2].string = str_df_main正在替换字符串(如果我错了请纠正我)
我用的是 table[2].replace_with(BeautifulSoup(str_df_main, 'html.parser')) 附加了新的数据表