18910140161

HTML-如何在Python中提取标记href-堆栈溢出

顺晟科技

2022-10-18 12:34:27

145

我想从一个类中提取一个href标签,我该怎么做?这是我的代码:

from bs4 import BeautifulSoup
import requests
from pprint import pprint
def search_manga(titolo):
    i = 0
    e = 0
    base_url = "https://beta.mangaeden.com/it/it-directory/?title="
    titolo = titolo.replace(" ", "+")
    url = base_url + titolo
    r = requests.get(url)
    soup = BeautifulSoup(r.content, "html.parser")
    manga_list = soup.find(id = 'mangaList')
    a_tag = manga_list.find_all(class_='openManga')
    print(a_tag)
    a_tag_array=[]
    for link in a_tag:
        link = a_tag.get('href')
        print(link)
manga_name = input("inserisci il nome del manga: ")
search_manga(manga_name)
输出

如下:

AttributeError:ResultSet对象没有属性“ Get ”。您可能将元素列表视为单个元素。当您打算调用find()时,是否调用了find_all()?

该怎么解决?


顺晟科技:

查看查询的HTML响应,似乎只有一个元素具有类“ OpenManga ”。因此,这可以简化如下:

AttributeError: ResultSet object has no attribute 'get'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航