Search

Invoke-WebRequest / getElementsByTagName is incredibly slow on some machines by DanTup

Active

2
0
Sign in
to vote
Type: Bug
ID: 778371
Opened: 2/2/2013 11:00:00 AM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
I've posted full details and a sample on StackOverflow here:

http://stackoverflow.com/questions/14202054/why-is-this-powershell-code-invoke-webrequest-getelementsbytagname-so-incred/14657508?iemail=1

I have some code that uses Invoke-WebRequest to fetch a web page, and then use .ParsedHtml.body.getElementsByTagName to scrape some info from the site.

However, the getElementsByTagName call seems to take a *long* time for me (around 1.5seconds per call) on all three machines I've tested it on (Windows 7 Home Premium, Windows 7 Enterprise, Windows 8). Other people see sub-100 millisecond times running the same code.

There's more discussion about this issue on Google+ here:
https://plus.google.com/communities/114336958783305019912

I can't find any common pattern between machines that do/don't have this issue. It occurs for me with no PS profile, in both ISE and the console. I have VS 2012 (and therefore .NET 4.5) installed on two of the machines, but not the third.
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

I don't know if this issue existed previously
Reproduction Steps
Run the following code:

$url = "http://www.icy-veins.com/restoration-shaman-wow-pve-healing-gear-loot-best-in-slot"
$response = (iwr $url).ParsedHtml

# Loop through the h2 tags
$response.body.getElementsByTagName("h2") | foreach {

    # Get the table that comes after the heading
    $slotTable = $_.nextSibling

    # Grab the rows from the table, skipping the first row (column headers)
    measure-command { $rows = $slotTable.getElementsByTagName("tr") | select -Skip 1 } | select TotalMilliseconds
}
Expected Results
Except to get short times, like this sample from somebody in the Google+ Community:

TotalMilliseconds
-----------------
         76.9098
         112.6745
         56.6522
         140.5845
         84.9599
         48.6669
         79.9283
         73.4511
         94.0683
         81.4443
         147.809
         139.2805
         111.4078
         56.3881
         41.3386

However, I get this:

TotalMilliseconds
-----------------
        1575.7633
        2371.5566
        1073.7552
        2307.8844
        1779.5518
        1063.9977
        1588.5112
        1372.4927
        1248.7245
        1718.3555
         3283.843
        2931.1616
        2557.8595
        1230.5093
         995.2934
File Attachments
0 attachments
Sign in to post a comment.
Sign in to post a workaround.