0
votes

I know we are supposed to add as many details as possible, but I do not know much about how this works, so my details will be minimum. I am not sure if this is the correct/best way to do this, so please go easy on me. Here is my situation:

I want to get information from a webpage. I can't give you the webpage because it's internal to a company. Basically the webpage has a form with a bunch of text-boxes and a couple buttons (one being submit). I want to programmatically (with PowerShell - or maybe something else like Python if it would work better) web request the page to submit a piece of information and get the results.

I basically have a list of names that I need to loop through. Done manually, each name would be pasted into one of the text-boxes on the page, the submit button would be clicked, and the results would pop up.

I want to loop through the list of names and perform a post webrequest on each item, then grab the results. Can this be done with PowerShell?

I have been messing around with Invoke-WebRequest, but I am not entirely sure how it works. I am pretty sure that the webpage can have post requests performed on it because when I execute

$req = Invoke-WebRequest -URI https://www.foobar.com -Method Post

I do not get any errors about the webpage not accepting posts. Any advice?

Here is some relevant code from the webpage:

<button class="Button k-button k-button-first SearchButton" data-categorytext="#SearchByValue, #ServerRequestValue" data-summary="" id="btnSearch_SearchBy">Search</button>
<script>
    jQuery(function(){jQuery("#btnSearch_SearchBy").kendoButton({});});
</script>

The textbox that I need to provide information to

<input class="k-textbox SearchField" data-summary="Server Name like " id="ServerNameSearchValue" name="ServerNameSearchValue" style="width: 300px;" type="search" value="SOME_SERVER_NAME_FROM_MY_LIST" />

When the form is submitted, a window pops up on the page with the results. The page does not reload or anything, so would I need to perform a get request on the page after I perform the post request to get the information from the new window?

1

1 Answers

0
votes

You need to specify the POST parameters to send in a Hasthable:

# Name is the field name on the form
$params = @{Name = 'Some Name'}
$results = Invoke-WebRequest -Uri http://example.com/foobar -Method POST -Body $params

You can get the comboboxes/textboxes by looking at the generated HTML and adding them to the array like this:

$params = @{TextBox1 = 'Some Name'; TextBox2 = 'Some Name'}

You can also use a GET request with Invoke-WebRequest, then parse the HTML to get the textbox names and build the array above with the names and values. That's more complex but valuable if you want to make your code more generic.

However, no matter what, you will have to set the values of those comboboxes/textboxes in your Powershell script.