英文:
Retrieve 'Page Source' content, like in firefox via right click then 'View Page Source'
问题
在Firefox中,您可以右键单击任何页面,然后单击“查看页面源代码”,这将为您提供一些看起来像HTML的代码。我希望在PowerShell中做同样的事情。有许多时候我发现自己需要这样做,我想要一个PowerShell的方法。
我试图找到一种在PowerShell中获取YouTube频道的一致方法。这篇文章似乎提供了一种可靠的方法,但它依赖于Firefox中找到的这个查看页面源代码方法。
所以我尝试了以下代码:
$var = invoke-WebRequest -URI https://www.youtube.com/@houdini3d/featured
这确实返回了关于页面的一些HTML信息。
StatusCode : 200
StatusDescription : OK
Content : <!DOCTYPE html><html lang="en-GB" dir="ltr"><head><style nonce="sNb8Va34AquZa4m4EwgJTg">
a, a:link, a:visited, a:active, a:hover {
color: #1a73e8;
text-decoration: none;
}
body {
font-family: Ro…
RawContent : HTTP/1.1 200 OK
我尝试将Firefox窗口中的文本内容与$Var.RawContent
中的值进行比较。它们似乎不是相同的东西。我还检查了$var.Content
,也不相同。
通过比较,我是指在文本编辑器中手动比较它们。
invoke-WebRequest -URI https://www.youtube.com/@houdini3d/featured
是错误的方法吗?
我不懂任何Web“编程语言”如HTML/CSS,所以我对此一无所知。
英文:
In Firefox you can right click on any page, then click on View Page Source
, this will give you some code that looks to be HTML.
I am looking to do the same thing in PowerShell. There are many times I have found myself doing this and would like to have a PowerShell approach.
I am trying to find a consistent way of obtaining the Chanell ID of a YouTube channel, in PowerShell. THIS guide seems to be offering a reliable method but it relies on this very View Page Source method found in Firefox.
So I have tried
$var = invoke-WebRequest -URI https://www.youtube.com/@houdini3d/featured
This does return some HTML information about the page.
StatusCode : 200
StatusDescription : OK
Content : <!DOCTYPE html><html lang="en-GB" dir="ltr"><head><style nonce="sNb8Va34AquZa4m4EwgJTg">
a, a:link, a:visited, a:active, a:hover {
color: #1a73e8;
text-decoration: none;
}
body {
font-family: Ro…
RawContent : HTTP/1.1 200 OK
I tried comparing the text content from a Firefox window and the value in $Var.RawContent
. They don't seem to be the same thing. I also checked $var.Content
not the same either.
by comparing I mean manually by in a text editor.
Is invoke-WebRequest -URI https://www.youtube.com/@houdini3d/featured
the wrong way to go about this?
I don't know any web "Programming Languages" like HTML/CSS, so I am in the dark here.
答案1
得分: 2
你可以使用Internet Explorer ComObject来完成这个任务。
$IE = New-Object -ComObject InternetExplorer.Application
$IE.Navigate('https://www.youtube.com/@houdini3d')
While($IE.Busy){Start-Sleep -Second 1}
If($IE.Document.IHTMLDocument2_body.innerHTML -match 'browse_id","value":"(.+?)"'){ $Matches[1] } else { '未找到频道ID' }
英文:
You can use an Internet Explorer ComObject to do this.
$IE = New-Object -ComObject InternetExplorer.Application
$IE.Navigate('https://www.youtube.com/@houdini3d')
While($IE.Busy){Start-Sleep -Second 1}
If($IE.Document.IHTMLDocument2_body.innerHTML -match 'browse_id","value":"(.+?)"'){$Matches[1]}else{"Channel ID not found"}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论