0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Elasticsearch の plug-in のサイトをxpathを使用して検索&表示してみる

Last updated at Posted at 2020-06-04

#目的
Windows10 + Python3 + selenium + chromedriver + headless chrome で Elasticsearchの plugin 用のサイトをアクセスしてみる
Fessのメンテや新規インストール時にElasticsearchのpluginのバージョンチェックが楽にできないかな?
とりあえずのテストコードを作成
※仕様は未定 plugin は決め打ちなので直接みに行けばいいんじゃないかと
org/codelibsをローカルに保存してテストを行う
#サンプルコード

# Windows Add env PYTHONIOENCODING = UTF-8 & restart vscode

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import chromedriver_binary

# plugin のリスト
alist = [
    'elasticsearch-analysis-extension/',
    'elasticsearch-analysis-fess/',
    'elasticsearch-configsync/',
    'elasticsearch-dataformat/',
    'elasticsearch-minhash/'
]

# ブラウザーを起動
options = Options()
options.binary_location = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)

# driver.get('https://repo1.maven.org/maven2/org/codelibs/')
# 上記をローカルに保存
driver.get('http://localhost:8080/codelibs.html')

try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.TAG_NAME, 'a'))
    )

    # xpath はこれで良いのだろうか?
    xpath = "/html/body/main/pre/a"
    elems = driver.find_elements_by_xpath(xpath)
    
    # listに存在する link text を表示する
    for elem in elems:
        if elem.text in alist:
            print(elem.text)

finally:
    print('done')
    driver.quit()

#参考にしたサイトはこちら
WebElement 内部を find_element_by_xpath() で再検索した時のつまずき
Python/Seleniumで便利なxpath検索をする方法!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?