我正在使用 BeautifulSoup 從此頁(yè)面中提取所有鏈接:http : //kern.humdrum.org/search?s=t&keyword=Haydn我通過(guò)這種方式獲得所有這些鏈接:# -*- coding: utf-8 -*-from urllib.request import urlopen as uReqfrom bs4 import BeautifulSoup as soupmy_url = 'http://kern.humdrum.org/search?s=t&keyword=Haydn'#opening up connecting, grabbing the pageuClient = uReq(my_url)# put all the content in a variablepage_html = uClient.read()#close the internet connectionuClient.close()#It does my HTML parserpage_soup = soup(page_html, "html.parser")# Grab all of the linkscontainers = page_soup.findAll('a', href=True)#print(type(containers))for container in containers: link = container #start_index = link.index('href="') print(link) print("---") #print(start_index)我的部分輸出是:請(qǐng)注意,它返回了幾個(gè)鏈接,但我真的想要所有帶有 >Someting 的鏈接。(例如,“> Allegro”和“Allegro vivace”等等)。我很難獲得以下類(lèi)型的輸出(圖像示例):“快板 - http://kern.ccarh.org/cgi-bin/ksdata?location=users/craig/classical/beethoven/piano/奏鳴曲&文件=奏鳴曲01-1.krn&格式=信息“換句話(huà)說(shuō),在這一點(diǎn)上,我有一堆錨標(biāo)簽(+- 1000)。從所有這些標(biāo)簽中,有一堆只是“垃圾”和 +- 350 個(gè)我想提取的標(biāo)簽。所有這些標(biāo)簽看起來(lái)幾乎一樣,但唯一的區(qū)別是我需要的標(biāo)簽?zāi)┪灿幸粋€(gè)“>某人的名字<\a>”。我只想提取具有此特征的所有錨標(biāo)記的鏈接。
使用 BeautifulSoup 從 <a href 標(biāo)簽中提取特定頁(yè)面鏈接
尚方寶劍之說(shuō)
2021-08-14 17:11:13