私が何か間違っていると説明した場合、これが私を許してください。特定のURLからのリンクを掻き立てる
私は、特定のWebサイトからpythonでスクレイプURLを取得しようとしており、csvへのリンクを解析しています。問題は、BeautifulSoupのWebサイトを解析するときです。私はURLを抽出できません。なぜなら、Pythonで解析すると、そのブランチの下にある<div id="dvScores" style="min-height: 400px;">\n</div>,
しか取得できないからです。しかし、コンソールを開いてリンクがあるテーブルをコピーしてテキストエディタに貼り付けると、600ページのhtmlが貼り付けられます。私がしたいのは、リンクを表示するforループを書くことです。 htmlの構造は次のとおりです。
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
#shadow-root (open)
<head>...</head>
<body>
<div id="body">
<div id="wrapper">
#multiple divs but i don't need them
<div id="live-master"> #what I need is under this div
<span id="contextual">
#multiple divs but i don't need them
<div id="live-score-master"> #what I need is under this div
<div ng-app="live-menu" id="live-score-rightcoll">
#multiple divs but i don't need them
<div id="left-score-lefttemp" style="padding-top: 35px;">
<div id="dvScores">
<table cellspacing=0 ...>
<colgroup>...</colgroup>
<tbody>
<tr class="row line-bg1"> #this changes to bg2 or bg3
<td class="row">
<span class="row">
<a href="www.example.com" target="_blank" class="td_row">
#I need to extract this link
</span>
</td>
#Multiple td's
</tr>
#multiple tr class="row line-bg1" or "row line-bg2"
.
.
.
</tbody>
</table>
</div>
</div>
</div>
</div>
</span>
</div>
</div>
</body>
</html>
私は間違っていますか?私はPythonのために、HTMLをテキストに貼り付けたり、正規表現でリンクを抽出するのではなく、システムを自動化する必要があります。 私のPythonコードは、以下である:
import requests
from bs4 import BeautifulSoup
r=requests.get("http://example.com/example")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("span",id="contextual")
span=all[0].find_all("tbody")
希望の出力を指定できますか?それはURLのようです: 'http:// www.mackolik.com/Mac/2581146/Kayserispor-Osmanlıspor-FK'? – vold
@voldはい正しい。すべての試合にはチームの名前の間にリンクがあります。それが私が抽出したいリンクです。 – Gorkem