seleniumとBeautifulSoupを使って、Yahooニュースでスクレイピングをしようとしています。
seleniumでchromeから自動検索して検索結果のページのソースを回収したいと思っているのですが、
ページ下部の「もっと見る」をクリックして記事の表示数が増えた後のソースを入手しようとしても、クリック前と同じソースしか手に入れることができません。
URLがクリック前と後で変わらないので、それが原因のひとつかなとは思っています。
これの解決方法はありますでしょうか?
回答よろしくお願いいたします。
※BeautifulSoupで解析したいので、それが可能な方法だと嬉しいです。
使用しているコードは下記の通りです。(初心者が1 から書いているので見にくいかもしれません)
python
1from selenium import webdriver 2from selenium.webdriver.common.by import By 3from selenium.webdriver.chrome import service as fs 4from bs4 import BeautifulSoup 5import requests 6from time import sleep 7 8topic = input() 9 10chrome_service = fs.Service(executable_path='ファイルパス') 11driver = webdriver.Chrome(service=chrome_service) 12driver.get('https://news.yahoo.co.jp') 13form = driver.find_element(By.XPATH,'//*[@id="searchBoxWrap-header"]/form/div/div/div[1]/input[1]') 14form.send_keys(topic) 15form.submit() 16 17element = driver.find_element(By.XPATH,'//*[@id="contentsWrap"]/div/div[2]/div/div/span/button') 18element.click() 19sleep(3) 20 21top_url = driver.current_url 22top_responce = requests.get(top_url) 23top_soup = BeautifulSoup(top_responce.text, 'html.parser') 24type(top_soup)

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/18 08:10
2022/06/18 09:04
2022/06/24 08:05
2022/06/25 09:02
2022/06/25 10:50
2022/06/29 01:18
2022/07/08 03:11