0

I am currently attempting to use Powershell to scrape link pages from a specific site. Have knocked up a variation of the current code but it is essential the same.

I am attempting to get the URL for the search google search result. I have added the below screenshot to explain what i am hoping to grab.

enter image description here

I so far have the following code which is converting the text to a successful search and is working as expected.however when called with the Invoke-WebRequest i dont get any meaningful results. when using a browser with the link it works sucsessfully

function Get-GoogleSEQueryString 
{
    param([string[]] $Query)

    Add-Type -AssemblyName System.Web # To get UrlEncode()
    $QueryString = ($Query | %{ [Web.HttpUtility]::UrlEncode($_)}) -join '+'

    # Return the query string
    $QueryString
}

$SearchString = "Requiem for an American Dream"
$QueryString = Get-GoogleSEQueryString $SearchString
$url = "http://www.google.com.au/?gfe_rd=cr&ei=ZuzTV_v6B7Du8weC8qsY#q="+$QueryString+"+site:IMDB.com"

#(Invoke-WebRequest -Uri $url).links | Where-Object {$_.href -like "http*"}

$t = Invoke-WebRequest -uri $url
$t.AllElements | Where {$_.innerhtml -like '*=*'} |Sort { $_.InnerHtml.Length } | Out-GridView

Can anyone kindly assist in regards to this problem?

4

1 に答える 1

1

コメントを回答として要約すると、Google のメイン検索ページには HTML に検索結果が含まれていません。いくつかのコンテナーしかなく、ページの読み込み中に読み込まれ、HTML DOM に動的に入力されます。

ページをダウンロードすると、結果のないコンテナー HTML のみが取得されます。Google の検索結果ページで [ソースを表示] を選択すると、実際に同じものが表示されます。

他の検索エンジンを試すか、Web サービスを使用してデータを取得できます。

Google の Web サービスについて詳しくは、https ://developers.google.com/custom-search/json-api/v1/reference/cse/list をご覧ください。

于 2016-09-12T11:10:54.750 に答える