excel - 访问网页中的主要 HTML 文档以使用 Selenium 自动化 Chrome
问题描述
我会通过单击我公司某个网页中的某个按钮和链接序列来自动下载 CSV。
但是,通过查看页面源代码,该网页没有显式的 HTML 元素;它显示如下:
<HTML ><head><title></title>
<script language="javascript" src="23048/scripts/swecommon.js?_scb="></script>
<script language="javascript" src="23048/scripts/swecmn_hi.js?_scb="></script>
</head><body leftmargin="8" topmargin="2" marginwidth="20" marginheight="2" class="ScreenBack"><script>
if(typeof(window._swescript)!='undefined'&&window._swescript!=null) window._swescript.InitFrame(this);</script>
<h1><span class="AppletTitle">Session Warning Message</span></h1><h4><span class="error">You have initiated a Siebel session while another Siebel session is currently active. Please choose the option that applies to you.</span></h4><ul><li><span class="error">You already have a Siebel session with unsaved data running in another browser window. To save data from a second session go to the already open session and either save and exit or continue to use that data.</span></li><li><span class="error">You do not have unsaved data in your other session and wish to close it and launch a new session. </span><span class="error">Click </span><a href='JavaScript:void(0)' onclick='SWEClearHistoryGotoURL ("start.swe?SWENeedContext=false&SWECmd=Logoff&SWEC=14&SWEBID=-1&SRN=&SWETS="); return false;' target="_top" id='s_swepi_2'>here</a></li><li><span class="error">You have closed your previous Siebel browser instance using the Close instead of the Logoff feature and wish to open a new Siebel session. </span><span class="error">Click </span><a href='JavaScript:void(0)' onclick='SWEClearHistoryGotoURL ("start.swe?SWENeedContext=false&SWECmd=Logoff&SWEC=14&SWEBID=-1&SRN=&SWETS="); return false;' target="_top" id='s_swepi_2'>here</a><script>
trackChange("");
SWEIsHighInteract = true; Top().SWEIsHighInteract = true;
if (typeof(window._samePage) != 'undefined' && window._samePage!="") window._samePage = "";
if (top.opener == null || typeof top.opener.swetop == 'unknown' || typeof top.opener.swetop == 'undefined') top.SiebelApp.S_App.SWECount = 14;
else top.opener.top.SiebelApp.S_App.SWECount = 14;
g_bInitialized = true;
</script>
</li></ul>
但是,当我尝试检查链接或按钮时,它会显示一个 HTML 文档,我认为我可以通过 Selenium 方法对其进行解析。
VBA 中的代码不适用于这个奇怪的网页,它适用于像 Facebook 这样的简单网页:
Sub TestSelenium()
Dim ChDriver As New webdriver
ChDriver.Start "Chrome"
ChDriver.get "https://chromedriver.storage.googleapis.com/index.html?path=83.0.4103.39/"
Application.Wait Now + TimeValue("00:00:05")
Stop
ChDriver.FindElementByXPath("/html/body/table/tbody/tr[6]/td[2]/a").Click
Stop
End Sub
提前谢谢。
解决方案
推荐阅读
- node.js - AWS 链接 Dynamo DB 和 S3 存储桶
- python - 如何使此 python 代码输出 0 1 4 6
- python - Python Mocking - 如何模拟正则表达式
- r - 以 R 语法导出 Plotly
- javascript - 无法使用 javascript 访问嵌套的 json 元素
- java - Java - 打印唯一的数字序列
- java - 从存储中检索我的文档时出现问题 - hibernate、springboot、java、sql 应用程序
- angular - 如何添加 Firebase Image URL 以输入并提交到数据库
- bash - 将小写文件夹重命名为大写
- planning - 自动规划:是什么让“blocksworld”成为一个不平凡的问题?