在问题#56107的回答中,Erlend提供了这个示例c#代码:
using mshtml;
...
object[] oPageText = { html };
HTMLDocument doc = new HTMLDocumentClass();
IHTMLDocument2 doc2 = (IHTMLDocument2)doc;
doc2.write(oPageText);
Run Code Online (Sandbox Code Playgroud)
我想在VB.NET中使用mshtml,但IDE无法识别:
Imports mshtml
Run Code Online (Sandbox Code Playgroud)
在VB.NET中使用MSHTML需要采取哪些额外步骤?
我有一个令人沮丧的问题.这是我正在做的简化版本:
c#中的UserControl包含工具栏和嵌入式WebBrowser对象.工具栏包含一个"编辑"按钮,单击该按钮可在设计模式下设置Web浏览器控件.另一个按钮"取消"关闭设计模式.
伪代码(非常简化):
public void SetDesignMode(bool dm) {
IHTMLDocument2 doc = webBrowser.Document as IHTMLDocument2;
if (dm) doc.designMode = "On";
else doc.designMode = "Off";
_designMode = dm;
ReloadDocument(); // setting designmode clears the document element, so it must be reloaded
}
public void OnLoadCompleted() {
IHTMLDocument2 doc = webBrowser.Document as IHTMLDocument2;
if (!_documentLoaded) {
if (_designMode) doc.designMode = "On";
else doc.designMode = "Off";
ReloadDocument();
_documentLoaded = true;
}
}
public void ReloadDocument() {
_documentLoaded = false;
// code that navigates to …Run Code Online (Sandbox Code Playgroud) 我有点困惑,也许你可以帮助我.
我有mshtml.dll(版本8.0)和Microsoft.mshtml.dll(版本7.0)
如果我去添加对我的WPF项目的引用并尝试添加mshtml.dll,它会告诉我引用必须是有效的程序集或com组件.这是正确的,因为我知道我必须添加对Microsoft.mshtml.dll的引用,因为它是mshtml.dll的包装器,我是对的吗?
现在,我的mshtml.dll版本是8.0,Microsoft.mshtml是7.0.
我在哪里可以找到8.0版本的Microsoft.mshtml.dll?
如果我添加了Microsoft.mshtml.dll的7.0,它将运行mshtml 8 dll的功能?
他们为什么不同?
非常感谢Jayson
我想使用MSHTML来获取html元素的样式.
我想要的是计算的样式,但没有所有默认值.(只有在html和css中设置的那些)
到目前为止,MSHTML有三种类型的样式,样式,currentStyle和runtimeStyle.
style和runtimeStyle只有内联样式,而当前样式包含所有内容,包括继承样式和默认样式.
有没有办法获得当前设置的样式(内联,外部和内部css)但没有所有继承和默认值?
必须有一种方法可以做到这一点,IE开发人员工具栏似乎知道从哪里继承了哪些样式.
您可能会首先认为由于XSS限制而无法实现.但我正在尝试从托管WebBrowser网站的应用程序访问此内容,而不是来自网站中的javascript代码.
我理解是不可能的,并且不应该通过非hacky手段从javascript访问此内容,因为这将是一个很大的安全问题.但是从托管a的应用程序中获得此限制是没有意义的WebBrowser.如果我想加强我的应用程序用户的Facebook信息,我可以做一个Navigate("facebook.com")并做我想做的任何事情.这是一个托管WebBrowser网页的应用程序,而不是网页.
另外,如果你用谷歌浏览器转到包含一个iFrame其源是在另一个领域,然后右键单击它的内容,然后单击检查元素任何网页时,它会告诉你的内容.更简单的是,如果您导航到包含其他域中的iFrame的任何网页,您将看到其内容.如果您可以在上面看到它WebBrowser,那么您应该能够以编程方式访问它,因为它必须位于内存中的某个位置.
有什么办法,而不是从DOM对象,因为他们似乎是基于相同的引擎,如JavaScript,因此通过XSS限制的限制,但是从一些低级别的对象,如MSHTML或SHDocVw,访问此文字?
我写了一个宏,它将打开一个网页,找到我需要放入数据的点,然后我想让宏点击一个预填充按钮,然后点击确定.
该按钮的页面源代码是:
<input type="text" size="30" maxlength="40" name="name" id="name">
<input type="button" value="Prefill" onclick="prefill()">
Run Code Online (Sandbox Code Playgroud)
我整个星期都在寻找答案,我想我已经基本了解了这应该是如何通过运行循环来搜索它,但我没有运气,我的努力实际上让它工作.
有人能告诉我将在我的页面上搜索此按钮的循环吗?
先感谢您.
到目前为止请求的代码
Private Sub Populate_Click()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "website" 'make sure you've logged into the page
Do
DoEvents
Loop Until IE.READYSTATE = 3
Do
DoEvents
Loop Until IE.READYSTATE = 4
ActiveSheet.EnableCalculation = False
ActiveSheet.EnableCalculation = True
Call IE.document.getelementbyid("name").SetAttribute("value", ActiveSheet.Range("b2").Value)
Call IE.document.getelementbyid("aw_login").SetAttribute("value", ActiveSheet.Range("a2").Value)
Set objCollection = …Run Code Online (Sandbox Code Playgroud) 我当前的代码适用于iframe之外的元素.我应该如何使用getElementById在iframe中获取元素?我的最终目标是在<body id="tinymce"><p>...</p></body>标签内写文字.我没有使用webBrowser控件 - 这是针对iexplore的外部实例
HTML示例

代码示例
foreach (InternetExplorer ie in new ShellWindowsClass())
{
if (ie.LocationURL.ToString().IndexOf("intranet_site_url") != -1)
{
IWebBrowserApp wb = (IWebBrowserApp)ie;
while (wb.Busy) { Thread.Sleep(100); }
HTMLDocument document = ((HTMLDocument)wb.Document);
// FETCH BY ID
IHTMLElement element;
HTMLInputElementClass hitem;
element = document.getElementById("tinymce");
hitem = (HTMLInputElementClass)element;
hitem.value = first_name;
// FETCH BY ID in IFRAME
IHTMLFramesCollection2 hframes = document.frames;
for (int i = 0; i < hframes.length; i++)
{
object ref_index = i;
IHTMLWindow2 currentFrame = (IHTMLWindow2)hframes.item(ref ref_index);
if …Run Code Online (Sandbox Code Playgroud) 从 MSDN 来看,返回类型只是“object”。
但是,如果您想操作元素,则返回的此对象可以强制转换为 mshtml.HTMLDocument,或者如果您想注册事件回调,则可以将同一对象强制转换为 (mshtml.HTMLDocumentEvents2_Event)。
在 MSHTML参考中中,定义了很多接口。但尚不清楚这些接口如何与 WPF WebBrowser.Document 对象一起使用
如果返回的对象是COM对象,那么它是什么?此 WPF WebBrowser.Document和 Windows 窗体WebBrower.Document 有什么不同?
示例代码:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)_browser.Document;
IHTMLElement bt = doc.getElementById("123");
mshtml.HTMLDocumentEvents2_Event iEvent = (mshtml.HTMLDocumentEvents2_Event)_browser.Document;
iEvent.onclick += new HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);
Run Code Online (Sandbox Code Playgroud) 我试图在C#WebBrowser控件(WPF而不是WinForm)中加载一个网页.与其他内容一起,页面具有图像旋转器,其动态地创建具有相同类的两个div以利用旋转的图像.在LoadComplete eventWebBrowser控件中,我附加了一个样式表来隐藏两个div.动态加载页面的两个div是:
<div class="backgroundImageDivsClass" style="
width: 100%;
height: 100%;
position: fixed;
top: 0px;
left: 0px;
padding: 0px;
margin: 0px;
z-index: -9999;
opacity: 1;
background-image: url("data/767/Course/9214/1000000001_474030834.jpg");
background-position: left top;
background-size: 100% 100%;
background-repeat: no-repeat;
"></div>
<div class="backgroundImageDivsClass"></div>
Run Code Online (Sandbox Code Playgroud)
并且在webbrowser控件的LoadComplete事件中分配css的方式是:
mshtml.IHTMLStyleSheet styleSheet = Document.createStyleSheet(string.Empty, 0);
styleSheet.cssText = @".backgroundImageDivsClass{display:none;}";
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,因为它没有隐藏div.有人请告诉我一些我缺少的东西.
我需要在 Windows 10(最新版本)下使用 VS2017 构建旧的 .NET 项目的小帮助。
我的问题是我需要以某种方式引用的“MSHTML”组件。通过References - Add - COM - Microsoft HTML Object Library这样做会导致以下构建错误:
warning MSB3283: Cannot find wrapper assembly for type library "MSHTML".
Verify that (1) the COM component is registered correctly and (2) your
target platform is the same as the bitness of the COM component.
For example, if the COM component is 32-bit, your target platform
must not be 64-bit.
Run Code Online (Sandbox Code Playgroud)
当我尝试直接引用C:\Windows\system32\mshtml.tlb时,会发生同样的错误。
我找到的唯一解决方案(例如,http : //techninotes.blogspot.ru/2016/08/fixing-cannot-find-wrapper-assembly-for.html)假设mshtml已经在 GAC 中我的情况:我在 …