我正在尝试从此页提取链接: http://www.tadpoletunes.com/tunes/celtic1/ 查看源:http://www.tadpoletunes.com/tunes/celtic1/ 但我只想要卷轴:在这一页中,卷轴的轮廓是: 开始时间:
<th align="left"><b><a name="reels">REELS</a></b></th>
结束(以下行上方):
<th align="left"><b><a name="slides">SLIDES</a></b></th>
问题是如何做到这一点。我有以下代码,它可以获取所有扩展名为.mid的链接:
def import_midifiles():
archive_url="http://www.tadpoletunes.com/tunes/celtic1/"
sauce= urllib.request.urlopen("http://www.tadpoletunes.com/tunes/celtic1/celtic.htm").read()
soup=bs.BeautifulSoup(sauce,'lxml')
tables=soup.find_all('table')
for table in tables:
for link in table.find_all('a',href=True):
if link['href'].endswith('.mid'):
listofmidis.append(archive_url + link['href'])
if listofmidis:
listoflists.append(listofmidis)
midi_list = [item for sublist in listoflists for item in sublist]
return midi_list
我不能从那些漂亮的医生那里搞清楚。我需要的代码,因为我将在其他网站上重复的活动,以刮数据训练模型。你知道吗
要获取所有“卷轴”链接,需要执行以下操作:
获取“卷轴”和“幻灯片”之间的链接,如你所说。为此,首先需要找到包含} 方法来完成。你知道吗
<a name="reels">REELS</a>
的<tr>
标记。这可以使用^{现在,您可以使用^{} 方法获取“revels”之后的所有
<tr>
标记。当找到带有<a name="slides">SLIDES</a>
(或.find('a').text == 'SLIDES'
)的<tr>
标记时,我们可以中断循环。你知道吗完整代码:
部分输出:
相关问题 更多 >
编程相关推荐