実現したいこと
以下のサイトでホットランキング女性向けのボタンを押したい
(内容が切り替わりリロードされる)
https://www.alphapolis.co.jp/novel/ranking/hot
前提
スクレイピングの勉強をしています。
上記のサイトで女性向けランキング情報を取得したいのですが、デフォルトは男性向け情報になっており、ボタンを押さないとサイトの情報が切り替わりません。
発生している問題・エラーメッセージ
立ち上がるブラウザを見ていますがボタンが押された様子がありません。
XPathでのボタン操作を試したのですがうまくいかず、切替そのものを行うjavascript関数を呼び出そうとしたのですがうまくいかないようです。
また、以下のようなエラーも出ています。
Error parsing cert retrieved from AIA (as DER):
ERROR: Couldn't read tbsCertificate as SEQUENCE
ERROR: Failed parsing Certificate
USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)
該当のソースコード
Python
PythonでSeleniumを使い以下のようなコードを書きました。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from bs4 import BeautifulSoup
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = Options()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--ignore-ssl-errors')
driver_path = "実際のdriverのパス"
service = Service(executable_path=driver_path)
browser = webdriver.Chrome(service=service,options=chrome_options)
url = "https://www.alphapolis.co.jp/novel/ranking/hot"
browser.get(url)
WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
print("Page fully loaded")
browser.set_window_size(1920, 1080)
#button = browser.find_element(By.XPATH,'//*[@id="ranking-for"]/li[2]')
#button.click()
browser.execute_script('changeGenre();')
time.sleep(20)
html = browser.page_source
soup = BeautifulSoup(html, 'html.parser')
filename = "hot.txt"
with open(filename, mode= "w" , encoding="utf-8") as f:
f.write(html)
browser.quit()
試したこと
CSS_SelecterではなくXPathでの指定、XPathではなくJavaScriptの実行
ブラウザを読み込むまで待つ処理を入れた
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
Python 3.10.11
Selenium 4.8.3

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/11 03:56
2023/04/11 06:46