【发布时间】:2020-09-21 07:27:22
【问题描述】:
我的本地文件夹中有一个 mhtml 文件,存储在 file_path 中,其中包含用户事件日志。我可以使用以下代码打开它:
with open(file_path, 'r') as fp:
message = email.message_from_file(fp)
for part in message.walk():
if (part.get_content_type() == "text/html"):
soup = BeautifulSoup(part.get_payload(decode=False), 'html.parser')
parsed_data = soup.prettify()
print(parsed_data)
下面是我使用上述代码得到的部分输出:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
function zoomToggle(num)
{
var img = document.getElementById("ss-" + num);
if (img.className == "screenshot") {
img.className = "screenshot-thumb";
}
else {
img.className = "screenshot";
}
return false;
}
</script>
<title>
Recorded Steps
</title>
</head>
<body>
<!-- This is the recorded XML data that was used in generating this page. -->
<xml id="recordeddata">
<script id="myXML" type="text/xml">
<?xml version="1.0" encoding="UTF-8"?>
<Report>
<System MajorVersion="10" MinorVersion="0" ServicePackMajor="0" ServicePackMinor="0" BuildNumber="18362" Sku="101" Platform="2" />
<UserActionData>
<RecordSession SessionCount="1" StartTime="11:51:58 AM" StopTime="11:52:39 AM" ActionCount="11" MissedActionCount="0">
<EachAction ActionNumber="1" Time="11:52:01 AM" Pid="8316" ProgramId="0000f519feec486de87ed73cb92d3cac802400000000" FileId="0000c07130e269ebfeefcb7d893f01498bc96aa5ab24" FileVersion="10.0.18362.1 (WinBuild.160101.0800)" FileDescription="Windows Explorer" FileCompany="Microsoft Corporation" FileName="EXPLORER.EXE" CommandLine="EXPLORER.EXE">
<Description>User left click on "Word - 1 running window (button)"</Description>
<Action>Mouse Left Click</Action>
<CursorCoordsXY>1383,1061</CursorCoordsXY>
<ScreenCoordsXYWH>0,0,1920,1080</ScreenCoordsXYWH>
<UIAStack>
<Level AutomationId="Microsoft.Office.WINWORD.EXE.15" BoundingRectangle="1358,1030,62,50" ControlType="50000" Name="Word - 1 running window" LocalizedControlType="button" />
<Level BoundingRectangle="610,1030,950,50" ClassName="MSTaskListWClass" ControlType="50021" FrameworkId="Win32" Name="Running applications" LocalizedControlType="tool bar" />
<Level BoundingRectangle="610,1030,950,50" ClassName="MSTaskSwWClass" ControlType="50033" FrameworkId="Win32" Name="Running applications" LocalizedControlType="pane" />
<Level AutomationId="40965" BoundingRectangle="608,1030,952,50" ClassName="ReBarWindow32" ControlType="50033" FrameworkId="Win32" LocalizedControlType="pane" />
<Level BoundingRectangle="0,1030,1920,50" ClassName="Shell_TrayWnd" ControlType="50033" FrameworkId="Win32" Name="Taskbar" LocalizedControlType="pane" />
</UIAStack>
<ScreenshotFileName>screenshot0001.JPEG</ScreenshotFileName>
</EachAction>
<EachAction ActionNumber="2" Time="11:52:03 AM" Pid="17892" ProgramId="00062dde378ad4a45da1a2e77a67bb6a717100000000"
之后还有多个 ... 。
我正在尝试使用 Python 检索 EachAction 选项卡中的功能。我无法找到解决方案。有人可以帮我解决这个问题吗?
谢谢
【问题讨论】:
-
你想要什么功能?你能发布预期的输出吗?
-
我正在尝试从所有“EachAction”选项卡中获取“ActionNumber”值、“Time”值和“FileDescription”值。此外,我还需要“操作”选项卡值。我需要为所有“EachAction”选项卡以表格格式保存所有这些数据。
标签: python beautifulsoup mhtml