Pergunta

I am trying to grab multiple elements from a website, but when I put either both parameters inside one set of parenthesis separated by comma I get "Cannot find an overload for "getElementsByTagName" and the argument count:"2". I even tried separating them out putting each element inside its own parens. Im running version 3.

$domDivs = Invoke-Webrequest "https://www.google.com/finance?q=NYSE%3AAMD&ei=R9KNU7DYB-musQeyhYH4Dg"
$domDivs.ParsedHtml.getElementsByTagName("div","p")| 
Select InnerText | 
Out-File "C:\TestFile.txt"
Foi útil?

Solução

You can only get one type of element per each getElementsByTagName invocation. Create a variable to store them in and pipe out later:

$domDivs = Invoke-Webrequest "https://www.google.com/finance?q=NYSE%3AAMD&ei=R9KNU7DYB-musQeyhYH4Dg"
$divsAndPs = $domDivs.ParsedHtml.getElementsByTagName("div") 
$divsAndPs += $domDivs.ParsedHtml.getElementsByTagName("p")
$divsAndPs | Select InnerText| Out-File "C:\TestFile.txt"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top