开发者

Finding table data via Internet Explorer COM

开发者 https://www.devze.com 2022-12-19 14:03 出处:网络
I am trying to automate a download of some data from a web a开发者_如何学Cpplication via Powershell/Internet Explorer COM similar to this article.

I am trying to automate a download of some data from a web a开发者_如何学Cpplication via Powershell/Internet Explorer COM similar to this article.

This works fine for normal elements/pull-downs, but how do navigate through tables via the COM object in case I want to click/find out the links inside a table?


Check this code:

$ie = New-Object -com InternetExplorer.Application
$tables = @($ie.Document.getElementsByTagName('table'))
# filter out the tables you are not interested in
$tables = filter-tables-somehow $tables
$links = $tables | 
  % { $_.getElementsByTagName('a') } |
  ? { filter-links-somehow $_ }
# and now process the links as you have been doing it so far

You need to filter out some tables that contain links that you don't want to download. The same holds for links - I suppose you want 'click' only some links.

For this kind of automation I would recommend to have a look at WatiN (or PowerWatiN). This could save you some time.


It looks like the standard DOM that people usually access in javascript. Try $doc.getElementsByTagName('TABLE') to get a list of tables. Use foreach or pipelines to get at the individual tables.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号