Created
December 9, 2018 10:07
-
-
Save nimzo6689/1731c7de8bc67c44e1fde06df30d27ea to your computer and use it in GitHub Desktop.
日常で書いたXPath式をとにかく保存しまくるページ
This file contains 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
Array.from($x('//*[@id="root"]/div/div/nav/ul/li/a[./h3[contains(text(), "conditional")]]/@href')) | |
.map(e => `${e.textContent}, title: ${e.ownerElement.textContent}`) |
This file contains 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
// ejje.weblio.jp/content/${word} | |
$x('//*[@class="EgtejRSpc"][2]') | |
// 品詞を取得する | |
$x('//*[@class="EgtejSub" and contains(text(), "詞")]') | |
// 品詞別に単語の解説を抽出したい場合 | |
$x(` | |
//span[@class="EgtejSub" and contains(text(), "形容詞")] | |
/following-sibling::div[@class="EgtejWrp"] | |
`) | |
// 品詞別に例文を抽出したい場合 | |
$x(` | |
//span[@class="EgtejSub" and contains(text(), "形容詞")] | |
/following-sibling::div[@class="EgtejWrp"] | |
/following-sibling::*[not(contains(@class, "EgtejYrAr"))] | |
`) |
This file contains 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
// ChomeやFireFoxのコンソールで実行する場合 | |
Array.from($x('xpath')).map(e => e.textContent) |
This file contains 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
# サードパーティを使用しないと、標準ではHTMLに対してXPathができない。 | |
Add-Type -Path $PsScriptRoot\HtmlAgilityPack.dll | |
$HAP= New-Object HtmlAgilityPack.HtmlDocument | |
$html= Invoke-RestMethod -Uri https://ejje.weblio.jp/content/jib | |
$HAP.LoadHtml($html) | |
$HAP.DocumentNode.SelectNodes('xpath') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment