September 25, 2020 at 2:33 am #258859ParticipantTopics: 2Replies: 0Points: 11Rank: Member
I am a newbie and making small progress 🙂 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):PowerShell12[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12<span class="hljs-variable">$web</span> = Invoke-WebRequest <span class="hljs-string">'<a href="https://www.gumtree.com.au/s-dogs-puppies/nsw/puppy/k0c18434l3008839" rel="nofollow">https://gumtree.com.au/s-dogs-puppies/nsw/labrador/k0c18434l3008839</a>'</span>
$count=([regex]::Matches($web.content, “labrador” )).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:
- 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.1
- This topic was modified 1 month ago by newbie8479.
- You must be logged in to reply to this topic.