Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created April 24, 2014 07:42
Show Gist options
  • Save dck-jp/11245322 to your computer and use it in GitHub Desktop.
Save dck-jp/11245322 to your computer and use it in GitHub Desktop.
PowerShell Sample
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