PowerShell的网页自动化的作品在互联网上,没有联网 [英] Powershell Web Page Automation works on Internet, not Intranet

查看:400
本文介绍了PowerShell的网页自动化的作品在互联网上,没有联网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做使用PowerShell一些简单的自动化,从我们公司的本地Intranet的一个网页链接拉动的URL,然后做与那些网址,一些工作。最后,我将使用脚本来打开每个链接,然后点击页面上的按钮。我使用的Internet Explorer 9在Windows 7 64位系统。

I'm trying to do some simple automation with Powershell, pulling link URLs from one of our company's local intranet pages, and then doing some work with those URLs. Eventually I'll use the script to open each link and click a button on the page. I'm using Internet Explorer 9 in Windows 7 x64.

下面是一个显示网页上的所有链接简单的工作PowerShell脚本的例子:

Here's an example of a simple working powershell script that displays all the links on a page:

$ie = new-object -com "InternetExplorer.Application"
$ie.Visible = $true
$ie.Navigate( "http://www.reddit.com" )
While ($ie.Busy) {
    Sleep 1
}

$links = $ie.Document.getElementsByTagName("a")
$links | foreach {
    write-host $_.href
}

,直到我用本地Intranet站点更换URL这个脚本工作正常。它遵循正常的URL方案( http://internaldomain.com/etc ),但它识别为一个内部网站。当我试图在Intranet区域刮的页面时,$ ie.Document值突然变得空和脚本失败。

This script works fine until I replace the URL with a local intranet site. It follows the normal URL scheme ( http://internaldomain.com/etc ), but it's recognized as an intranet site. Once I'm trying to scrape a page in the intranet zone, the $ie.Document value suddenly becomes NULL and the script fails.

我猜它是关系到该区域一些模糊的设定......我不知道。我发现了一些建议,网上如将它添加到您的信任网站,但是这并没有奏效。这是使用PowerShell的用于Web自动化我的第一次,所以任何帮助或洞察力将AP preciated。

I'm guessing it's related to some obscure setting for that zone... I'm not sure. I found some suggestions online such as adding it to your trusted sites, but that has not worked. This is my first time using Powershell for web automation, so any help or insight would be appreciated.

推荐答案

也许该解决方案是在这里:<一href=\"http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx

Maybe the solution is here: http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx

这解释了不同程度的标签,在IE中。您必须使用中等标签,在局部区域进行导航。

It explained the different levels of tabs, in ie. You have to use the "medium tab" to navigate in local zone.

基本上,保持你的IE设置和使用您的脚本最好的方法是创建一个注册表项,在上面的链接解释说。

Basically, the best way to keep your ie settings and use your script is to create a registry key, as explained in the link above.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium]

[HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium\CLSID] 
@="{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}"

而在你的脚本,使用这个新的COM对象:

And in your script, use this new com object:

$ie = new-object -Com InternetExplorer.ApplicationMedium
...

这篇关于PowerShell的网页自动化的作品在互联网上,没有联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆