这是我的第一个问题,如果我解释了任何错误,请原谅我。从特定网址上刮下链接
我想从python中的特定网站抓取url,并将链接解析为csv。事情是当我在BeautifulSoup解析网站我无法提取网址,因为当我在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