Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

javascript - Error coming while fetch items from multiple Instagram accounts

My Script

function Get-InstagramData() {
  $accounts = @("capitals", "monumental_sports", "washwizards", "washmystics")

$accounts | ForEach-Object {
    $url = "https://www.instagram.com/$_"
    $source = $_
    $response = Invoke-WebRequest -Uri $url -Method Get
    #$response.Content -match '<script type="text/javascript">window._sharedData = ([^;]*)'
    $response.Content -match '<script type="text/javascript">window._sharedData = ([^>]*)'
    $value = $Matches[0] -replace '<script type="text/javascript">window._sharedData = ', ''
    $value= $value -replace ';</script',''
    $json = $value | ConvertFrom-Json
    $cnt=0;

    $json.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges | ForEach-Object {
        if($cnt -lt 10)
        {
            $shortCode = $_.node.shortcode
            $thumbnaailSrc = $_.node.thumbnail_src
            $accessibilityCaption = $_.node.accessibility_caption
            $takenTimestamp = $_.node.taken_at_timestamp
            $captiontext = $_.node.edge_media_to_caption.edges[0].node.text
            # Write information to SP - up to 10 latest post from each account
            Set-PostInSharePoint -shortCode $shortCode -thumbnail $thumbnaailSrc -source $source -caption $accessibilityCaption -timestamp $takenTimestamp -imgcaption $captiontext 
        }
        $cnt++;
        }
    }
 }

Error:

 Cannot index into a null array.
     At line:15 char:9
    + $json.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_m
...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...