在Powershell中,有没有一种方法可以将html转换为具有深度的对象? [英] In Powershell, is there a way to convert html to a object with depth?

查看:73
本文介绍了在Powershell中,有没有一种方法可以将html转换为具有深度的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Powershell一起进行网络抓取试验,想知道是否有一种更简单的方法来处理元素?

I was working with Powershell to experiment with webscraping and wondered if there was an easier way to deal with elements?

有没有办法将HTML页面转换为Powershell中具有适当深度的对象?类似于Convert-ToJson -Depth吗?

Is there a way to convert an Html page to an object in powershell with proper depth? Something similar to Convert-ToJson -Depth?

例如,要获得一定的结果:

For example, to get a certain results:

$page = Invoke-WebRequest -uri $URI
Write-Host $page.html.body.div[4].a[5]

或者也许

$page = Invoke-WebRequest -uri $URI
$divs = $page.getElementsbyID("image-div")
$thumbs = $ $divs.getElementsbyID("thumbnails")
Write-host $thumbs[4]

Powershell中是否已经有一些附加组件或功能可以将html解析为具有深度的对象?

Is there some add-on or feature already in Powershell to parse the html to an object with depth?

推荐答案

是的,$page.ParsedHtml为您提供了对象结构.

Yes, $page.ParsedHtml gives you the object structure.

作为提示,您可以学习如何在PowerShell中发现此类功能:将对象传送到Get-Member以查看所有可用的属性/方法等.要快速查看所有属性是什么,可以进行传送到select *

As a tip for you to learn how to discover such functionality in PowerShell: Pipe your objects to Get-Member to see all available properties/methods, etc. And to quickly see what all the properties are, you can pipe it to select *

这篇关于在Powershell中,有没有一种方法可以将html转换为具有深度的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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