这是html代码
[<div class="last_episodes loaddub">
<ul class="items">
<li>
<div class="img">
<a href="/digimon-ghost-game-episode-36" title="Digimon Ghost Game">
<img alt="Digimon Ghost Game" src="https://gogocdn.net/cover/digimon-ghost-game.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/digimon-ghost-game-episode-36" title="Digimon Ghost Game">Digimon Ghost Game</a></p>
<p class="episode">Episode 36</p>
</li>
<li>
<div class="img">
<a href="/waccha-primagi-episode-41" title="Waccha PriMagi!">
<img alt="Waccha PriMagi!" src="https://gogocdn.net/cover/waccha-primagi.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/waccha-primagi-episode-41" title="Waccha PriMagi!">Waccha PriMagi!</a></p>
<p class="episode">Episode 41</p>
</li>
<li>
<div class="img">
<a href="/one-piece-episode-1027" title="One Piece">
<img alt="One Piece" src="https://gogocdn.net/images/anime/One-piece.jpg"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/one-piece-episode-1027" title="One Piece">One Piece</a></p>
<p class="episode">Episode 1027</p>
</li>
<li>
<div class="img">
<a href="/delicious-partyprecure-episode-21" title="Delicious Partyâ¡Precure">
<img alt="Delicious Partyâ¡Precure" src="https://gogocdn.net/cover/delicious-partyprecure.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/delicious-partyprecure-episode-21" title="Delicious Partyâ¡Precure">Delicious Partyâ¡Precure</a></p>
<p class="episode">Episode 21</p>
</li>
<li>
<div class="img">
<a href="/kingdom-4th-season-episode-17" title="Kingdom 4th Season">
<img alt="Kingdom 4th Season" src="https://gogocdn.net/cover/kingdom-4th-season.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/kingdom-4th-season-episode-17" title="Kingdom 4th Season">Kingdom 4th Season</a></p>
<p class="episode">Episode 17</p>
</li>
<li>
<div class="img">
<a href="/kingdom-4th-season-chinese-name-episode-17" title="Kingdom 4th Season (Chinese Name)">
<img alt="Kingdom 4th Season (Chinese Name)" src="https://gogocdn.net/cover/kingdom-4th-season-chinese-name.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/kingdom-4th-season-chinese-name-episode-17" title="Kingdom 4th Season (Chinese Name)">Kingdom 4th Season (Chinese Name)</a></p>
<p class="episode">Episode 17</p>
</li>
<li>
<div class="img">
<a href="/saikin-yatotta-maid-ga-ayashii-episode-2" title="Saikin Yatotta Maid ga Ayashii">
<img alt="Saikin Yatotta Maid ga Ayashii" src="https://gogocdn.net/cover/saikin-yatotta-maid-ga-ayashii.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/saikin-yatotta-maid-ga-ayashii-episode-2" title="Saikin Yatotta Maid ga Ayashii">Saikin Yatotta Maid ga Ayashii</a></p>
<p class="episode">Episode 2</p>
</li>
<li>
<div class="img">
<a href="/extreme-hearts-episode-4" title="Extreme Hearts">
<img alt="Extreme Hearts" src="https://gogocdn.net/cover/extreme-hearts.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/extreme-hearts-episode-4" title="Extreme Hearts">Extreme Hearts</a></p>
<p class="episode">Episode 4</p>
</li>
<li>
<div class="img">
<a href="/engage-kiss-episode-5" title="Engage Kiss">
<img alt="Engage Kiss" src="https://gogocdn.net/cover/engage-kiss.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/engage-kiss-episode-5" title="Engage Kiss">Engage Kiss</a></p>
<p class="episode">Episode 5</p>
</li>
<li>
<div class="img">
<a href="/kakkou-no-iinazuke-episode-14" title="Kakkou no Iinazuke">
<img alt="Kakkou no Iinazuke" src="https://gogocdn.net/cover/kakkou-no-iinazuke.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/kakkou-no-iinazuke-episode-14" title="Kakkou no Iinazuke">Kakkou no Iinazuke</a></p>
<p class="episode">Episode 14</p>
</li>
<li>
<div class="img">
<a href="/utawarerumono-futari-no-hakuoro-episode-6" title="Utawarerumono: Futari no Hakuoro">
<img alt="Utawarerumono: Futari no Hakuoro" src="https://gogocdn.net/cover/utawarerumono-futari-no-hakuoro.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/utawarerumono-futari-no-hakuoro-episode-6" title="Utawarerumono: Futari no Hakuoro">Utawarerumono: Futari no Hakuoro</a></p>
<p class="episode">Episode 6</p>
</li>
<li>
<div class="img">
<a href="/lycoris-recoil-episode-5" title="Lycoris Recoil">
<img alt="Lycoris Recoil" src="https://gogocdn.net/cover/lycoris-recoil.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/lycoris-recoil-episode-5" title="Lycoris Recoil">Lycoris Recoil</a></p>
<p class="episode">Episode 5</p>
</li>
<li>
<div class="img">
<a href="/musashino-episode-5" title="Musashino!">
<img alt="Musashino!" src="https://gogocdn.net/cover/musashino.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/musashino-episode-5" title="Musashino!">Musashino!</a></p>
<p class="episode">Episode 5</p>
</li>
<li>
<div class="img">
<a href="/shoot-goal-to-the-future-episode-5" title="Shoot! Goal to the Future">
<img alt="Shoot! Goal to the Future" src="https://gogocdn.net/cover/shoot-goal-to-the-future.png"/>
<div class="type ic-SUB"></div>
</a>
</div>
<p class="name"><a href="/shoot-goal-to-the-future-episode-5" title="Shoot! Goal to the Future">Shoot! Goal to the Future</a></p>
<p class="episode">Episode 5</p>
from urllib import response
from venv import create
from bs4 import BeautifulSoup
import requests
url = "https://gogoanime.gg?page=1"
req = requests.get(url)
Response = req.content
soup = BeautifulSoup(Response, 'html.parser')
p_tags = soup.find_all('p', class_='name')
a_tags = p_tags.find_all('a')
for link in a_tags:
links = link.get('href')
print(links)
我已经试过了,但仍然无法修复错误。我们将提前感谢您的帮助。
p_tags = p_tags = soup.find_all('p', class_='name')
for a_tags in p_tags.find_all('a')
print(a_tags)
有了这个,我得到了a标签,但当我尝试获取href时,我得到相同的错误,甚至我得到了href,不知为什么,它只是最后一个href,而之前应该有19个。
p_tags = soup.find_all('p', class_='name')
for a in p_tags:
a_tags = a.find_all('a')
print(len(a_tags))