スクレイピングで同じクラスが複数あるものを一つずつ指定するにはどのようにすればいいですか
Q&A
Closed
解決したいこと
こちらのサイトhttps://github.com/orangain/scraping-hands-on/blob/master/exercises.md でpythonのスクレイピングの練習しております。1つ目の問題で同じクラスが複数あり一番最初の一つだけしか取得できません。どのようにすれば一つずつ取得できますか?7
該当するソースコード
import requests
from bs4 import BeautifulSoup
url = "http://qiita.com/advent-calendar/2016/crawler"
html = requests.get(url)
soup = BeautifulSoup(html.content,'html.parser')
#木曜日1日
for link in soup.find(class_='style-1dctyxx'):
print(link.get('href'))
for element in soup.find(class_='style-3ki7ar'):
print(element.text)
#金曜日2日
for link in soup.find(class_='style-1dctyxx'):
print(link.get('href'))
for element in soup.find(class_='style-3ki7ar'):
print(element.text)
出力)
http://amacbee.hatenablog.com/entry/2016/12/01/210436
scrapy-splashを使ってJavaScript利用ページを簡単スクレイピング
http://amacbee.hatenablog.com/entry/2016/12/01/210436
scrapy-splashを使ってJavaScript利用ページを簡単スクレイピング
pythonのバージョンは3.11.2です。
0 likes