Invoke-Webrequest Forms feedback

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Michael W Michael W 1 year ago.

  • Author
  • #30908
    Profile photo of Michael W
    Michael W

    I've been hammering a (govermental website that handles companies in Sweden) , to get information about companies in Sweden to get output from the form-data there but I cant manage to do this.
    Website =

    I have put togheter this code but i cant seem to get the variables right in form. I understand that you need to use the fp-sok and select the radiobutton with fp-sok:type:0 and submit searchterm with fp-sok:sokterm but I have ran out of guessing combinations. Any guidance and it would be nice to get to know what I am doing wrong.

    The current code on where Im at:
    $url = ""
    $Fields = @{'fp-sok' = 'fp-sok:type:0';'fp-sok:sokterm' = '556762-6782','fp-sok:find'}
    $Bolagsverket = (Invoke-WebRequest $url -SessionVariable 'jsessionid=mHfhj5tCYVxTNMO9-q2AjKaV.JVM30-dh2-prod-jas36' -Method Post -Body $Fields)

    But I am only getting this, which is a kinda /ignore answer from the website;
    StatusCode : 200
    StatusDescription : OK
    Content :

    ; outerText=; tagNam
    e=IMG; alt=Bolagsverket; src=; width=200; height=33}, @{innerHTML=; innerText=; outerHTML=Kundva
                    gn ; outerText=; tagName=IMG; alt=Kundvagn ; src=img/kundvagn.png}}
    InputFields : {@{innerHTML=; innerText=; outerHTML=; outerText=; tagName=INPUT; type=hidden; value=fp-sok; name=fp-sok}
    , @{innerHTML=; innerText=; outerHTML=; outerText=; tagName=INPUT; id=fp-sok:type
    :0; CHECKED=; type=radio; value=1; name=fp-sok:type}, @{innerHTML=; innerText=; outerHTML=; outerText=; tagName=INPUT; id=fp-sok:type:1; type=radio; value=2; name=fp-sok:type}, @{innerHTML=; innerText=; outerHTML=; outerText=; tagName=INPUT; id=fp-sok:sokterm; maxLength=100; name=fp-sok:sokterm}...}
    Links : {@{innerHTML=Bolagsverket; innerText=; outerHTML=Bolagsverket; outerText=; tagName=A; title=Till Bolagsverkets webbplats; href=}, @{innerHTML=In English; innerText=In English; outerHT
    ML=In English; outerText=In English; tagName=A; lang=en; id=menuId1; href=/fpl-dft-ext-web/home.seam;jsessioni
    d=n7ZRxzSsEIrmgJXIB74NVrC9.JVM30-dh2-prod-jas36?sprak=en&actionMethod=home.xhtml%3Alanguage.bytSprak&cid=31478}, @{innerHTML=navigering; inne
    rText=navigering; outerHTML=navigering; outerText=navigering; tagName=A; accessKey=s; href=#omradesnav}, @{inne
    rHTML=Logga in; innerText=Logga in; outerHTML=Logga in; outerText=Logga in; tagName=A; id=j_id102; href=/fpl-dft-ext-web/login.seam;jsessionid=n7ZRxzSsEIrmgJXIB74NVrC9.JVM30-dh2-
    ParsedHtml : mshtml.HTMLDocumentClass
    RawContentLength : 8286

    When analyzing the form on the website by making the request manually using the browser, and with using the software Fiddler as the analyzer-tool and looking at the forms-tab, I'm getting these values. But I still cannot grasp how I need to handle this request;
    Name: Value:
    fp-sok:type 1
    fp-sok:sokterm 556762-6782
    fp-sok fp-sok
    javax.faces.ViewState j_id11
    fp-sok:find Search

    Please anyone, help 🙂
    Thanks guys!

  • #30913
    Profile photo of Steven Ayers
    Steven Ayers

    Whenever I'm trying to pull information like you are I tend to use httpwebrequest, there's lots of properties you can specify and may have functionality you are looking for, this script definitely won't do what you want it to, but you can see what I mean by how much more you have to play with.

    $username = '***************'
    $useragent = 'Microsoft Office/15.0 (Windows NT 6.2; Microsoft Outlook 15.0.4693; Pro)'
    $password = '**************'
    $domain = '************************'
    $Body = [byte[]][char[]]'asdf';
    $Request = [System.Net.HttpWebRequest]::CreateHttp('');
    $Request.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)
    $Request.Method = 'POST';
    $request.Timeout = "8000"
    $Request.ContentType = 'text/xml; charset=utf-8'
    $Request.UserAgent = "$useragent"
    $Stream = $Request.GetRequestStream();
    $Stream.Write($Body, 0, $Body.Length);

    Hope this is marginally helpful.

  • #31023
    Profile photo of Michael W
    Michael W

    Sorry Steven, I don't quiet see how your code-snippet would help me. Their website has public access. You could go there and search for "Facebook" for example to find the Swedish registered Facebook-company. That output is what I'm looking to return to the user.

    Anything or anyone else that could suggest/point me somewhere?

    Current code:

    $url = ''
    $InvokeWR = Invoke-WebRequest $url -SessionVariable JSESSIONID -Method Post

    $InvokeWR.Forms.Fields['fp-sok'] = 'fp-sok'
    $InvokeWR.Forms.Fields['fp-sok:type'] = '1'
    $InvokeWR.Forms.Fields['fp-sok:sokterm'] = 'facebook'
    $InvokeWR.Forms.Fields["fp-sok:find"] = 'Search'
    $InvokeWR.Forms.Fields["test"] = ''
    $InvokeWR.Forms.Fields["javax.faces.ViewState"] = 'j_id22'

    Its going through without any errors but I'm not getting any output *sigh*

You must be logged in to reply to this topic.