Created
April 24, 2014 07:42
-
-
Save dck-jp/11245322 to your computer and use it in GitHub Desktop.
PowerShell Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
$itemNum = 5 | |
) | |
# SeleniumVBAを用いてChromeを操作 _______________________________ | |
# _______________________________________________________________ | |
$driver = New-Object -ComObject SeleniumWrapper.WebDriver | |
$driver.start("chrome", "http://www.google.com") | |
$driver.open("/") | |
$driver.findElementByName("q",1000).SendKeys("メタ構文") | |
$driver.findElementByName("btnK",1000).Click | |
$driver.waitForTextPresent("関連する検索キーワード") | |
$title = [string[]]@() | |
for ($i = 1; $i -lt $itemNum+1; $i++) { | |
$title += $driver.findElementByCssSelector("li.g:nth-child($i) > div:nth-child(1) > h3:nth-child(1) > a:nth-child(1)",100).Text | |
} | |
$driver.close() | |
# Excelを操作 ___________________________________________________ | |
# _______________________________________________________________ | |
$excel = new-object -ComObject Excel.Application | |
$excel.Visible = $true | |
$newWorkbook = $excel.Application.Workbooks.Add() | |
$sheet1 = $newWorkbook.Worksheets.Item(1) | |
for ($i = 1 ; $i -lt $itemNum+1; $i++) { | |
$sheet1.Cells.Item($i,1) = $title[$i-1] | |
} | |
# Wordを操作 ____________________________________________________ | |
# _______________________________________________________________ | |
$word = new-object -ComObject Word.Application | |
$word.Visible = $true | |
$doc = $word.Documents.Add() | |
$range = $doc.Content | |
for ($i = 1 ; $i -lt $itemNum+1; $i++) { | |
$range.Text += $sheet1.Cells.Item($i,1).Text + "`n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment