スクレイピングが上手くいきません.
こちらのサイトを参考に
MapFanから地点の座標「33.8937792 130.9153766」を抜くことを目標に作業をしているのですが,bs4.Element.Resultsetから必要な文字列を抜き出すという事ができません.
調べてみると,bs4.Element.Resultsetは配列とのことだったので要素数をみてみると自分の戻り値であるbs4.Element.Resultsetは0でした.bs4.Element.Resultsetの中にbs4.Element.Tagなるものが入っているようですがそれの取り出しかたもよくわからないです.
python
1import requests 2from bs4 import BeautifulSoup 3 4url = "https://mapfan.com/spots/SCC,J,2V1" 5res = requests.get(url) 6#print(res.text) 7soup = BeautifulSoup(res.text, "lxml") 8#print(soup) 9#CSS 10elements = soup.select("body > mf-root > div > mat-sidenav-container > mat-sidenav-content > mf-spot > div > div > div:nth-child(3) > section > mf-spot-detail-base > mat-card > mat-card-content > section > table > tbody > tr.degree.mat-caption > td:nth-child(2) > span") 11#戻り値の形:bs4.element.Resultset 12print(len(elements))
あなたの回答
tips
プレビュー