首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Runspace的Powershell脚本

使用Runspace的Powershell脚本
EN

Stack Overflow用户
提问于 2018-02-05 05:22:04
回答 1查看 642关注 0票数 0

我是PowerShell的新手,只是为了练习,我得到了一些指导,“使用运行空间阅读array...then 100个URL,连接到每个URL,然后编写调用-WebRequest到文件的页面。”然后我得到了这个链接:https://www.zyxware.com/articles/4344/list-of-fortune-500-companies-and-their-websites

我一直在读关于跑步空间的书。现在,我正在努力将我的链接放到一个数组中,然后我可以将前100个URL从其中提取出来。如有任何帮助/建议,将不胜感激。

我现在的问题是,当我调用链接变量时,它不会给我链接。似乎我应该能够调用$link变量,这样我就可以获得所有的链接并将其放入数组中。我唯一能得到所有链接的方法是使用"$page.Links.href“。有人能给我解释一下为什么调用那个变量不起作用吗?

代码语言:javascript
复制
$page = Invoke-WebRequest https://www.zyxware.com/articles/4344/list-of-fortune-500-companies-and-their-websites

foreach($1 in $page.Links){
    if($1.href -like '*www*com'){
        Write-Host $1.href

        $link = $1.Links.href

    }
}

           $RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $Throttle)
$RunspacePool.Open()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-05 06:48:20

一步一步地走。

在做像运行空间这样高级的事情之前,你应该学习一些快速的PowerShell在线课程和材料,这样你就有了一个基线。尤其是你说你从来没有真正使用过PoSH。

https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276 query=beginner+powershell

有几个免费的eBooks在线.

https://powershell.org/ebooks

...as是一堆可下载的脚本,用于许多事情。

https://powershellgallery.com

还有长长的资源清单..。

Windows PowerShell生存指南https://social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide.aspx

首先,了解如何使用PoSH WebCmdlets。

代码语言:javascript
复制
Get-Command -Name Invoke-WebRequest| Format-Table -AutoSize

CommandType Name              Version Source                      
----------- ----              ------- ------                      
Cmdlet      Invoke-WebRequest 3.1.0.0 Microsoft.PowerShell.Utility


# Get paramter, example, full and Online help for a cmdlet or function

(Get-Command -Name Invoke-WebRequest|).Parameters
Get-help -Name Invoke-WebRequest| -Examples
Get-help -Name Invoke-WebRequest| -Full
Get-help -Name Invoke-WebRequest| -Online


Get-Command -Name Invoke-RestMethod | Format-Table -AutoSize

CommandType Name              Version Source                      
----------- ----              ------- ------                      
Cmdlet      Invoke-RestMethod 3.1.0.0 Microsoft.PowerShell.Utility


# Get paramter, example, full and Online help for a cmdlet or function

(Get-Command -Name Invoke-RestMethod ).Parameters
Get-help -Name Invoke-RestMethod  -Examples
Get-help -Name Invoke-RestMethod  -Full
Get-help -Name Invoke-RestMethod  -Online


Then search using the string 'Invoke-WebRequest to parse website for URLs'

Do that website URL parsing first, get that where you need it then move on to runspaces.
If you can't make the first part happen the runspaces is moot.

所以,试着用你放在一起的代码来获取URL,然后如果你对此有异议,发布你尝试过的内容,论坛就会尝试加入。同样的情况也适用于运行空间部分的第二步。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48616294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档