|  | 
 
| 
import requests
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  import bs4
 import re
 
 
 def open_url(url):
 headers={
 'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400'
 }
 res = requests.get(url,headers=headers)
 
 
 return res
 def find_animation(res):
 soup = bs4.BeautifulSoup(res.text,'html.parser')
 #动漫名
 animation = []
 targets = soup.find_all("li",class_="anime_icon2")
 for each in targets:
 animation.append(each.h4.a.text)
 #集数
 jishu = []
 targets = soup.find_all("span",class_="anime_icon1_name1")
 for each in targets:
 jishu.append(each.text)
 
 #找出一共多少个页面
 def find_depth(res):
 soup = bs4.BeautifulSoup(res.text,'html.parser')
 depth = soup.find('li',class_='pbutton  asciifont').previous_sibling.previous_sibling.text
 
 
 return int(depth)
 def main():
 host = "https://www.agefans.tv/recommend"
 res = open_url(host)
 depth = find_depth(res)
 
 result = []
 #length = len(animation)
 for i in range(depth):
 url = host + '/?start=' + str(25 * i)
 res = open_url(url)
 result.extend(find_animation(res))
 
 
 with open("age动漫推荐.txt","w",encoding="utf-8")as f:
 for each in result:
 f.write(each)
 
这句:depth = soup.find('li',class_='pbutton  asciifont').previous_sibling.previous_sibling.text
 我看了那个网站,li没有这个class,是下面的a有class。
 另外这个语句应该是不对的,应该改一下,你是想拿什么数据?
 
 | 
 |