Invoke-WebRequest process stuck in the middle

Hi All,

I am a newbie and making small progress :slight_smile: I am writing a simple test script to find how many times a specific keyword appears on a given site. The test example I am taking is from gumtree website - searching for keyword ‘puppy’

Here is the script that I have got (with someone’s help):

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$web = Invoke-WebRequest ''

$count=([regex]::Matches($web.content, “labrador” )).count
return $count`
Now the script works fine sometimes, the other times it will freeze while processing the webrequest. It doesnt move from :

“Reading response stream… (Number of bytes read: 186743)”

the number of bytes vary from time to time, but it stays on this for a while and then terminates giving a false much lower count of the keyword.

What I have tried so far:

  • -UseBasicParsing
  • I also tried dispose() thinking we need to release the resources, to do that I added $count= before the last line, and then tried adding $count.Dispose() however that gives me error --- InvalidOperation: Method invocation failed because [System.Int32] does not contain a method named 'dispose'
Any help with this is much appreacited.