# -*- coding: utf-8 -*- """ 电影人生 (dyrsok.com) 爬虫源 - 最终修复版 - 多线路完整提取 - 智能播放地址处理 (直链/API路径区分) - 超级线路/王者TV蓝光: 使用固定 cookie 请求下游 API """ import re, json, sys, requests from urllib.parse import urljoin, quote from bs4 import BeautifulSoup sys.path.append('..') from base.spider import Spider class Spider(Spider): host = "https://www.dyrsok.com" img_origin = "https://pic2.tupian.click" headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36', 'Referer': host + '/', 'Accept': 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'zh-CN,zh;q=0.9' } def getName(self): return "电影人生" def init(self, extend=""): super().init(extend) self.session = requests.Session() self.session.headers.update(self.headers) # 设置固定 cookie,让超级线路等 API 认证通过 self.session.cookies.set('ip_id', '69f2142514dcfe4bbe65fc6494043702', domain='.dyrsok.com') self.session.cookies.set('ip_id_ok', '1777472549', domain='.dyrsok.com') self.session.cookies.set('notice_closed', 'true', domain='.dyrsok.com') # ===== 首页 ===== def homeContent(self, filter): classes = [ {"type_id": "dianying", "type_name": "电影"}, {"type_id": "dianshiju", "type_name": "电视剧"}, {"type_id": "zongyi", "type_name": "综艺"}, {"type_id": "dongman", "type_name": "动漫"}, {"type_id": "duanju", "type_name": "短剧"} ] return {"class": classes, "list": self._get_home_videos()} def homeVideoContent(self): return {"list": self._get_home_videos()} def _get_home_videos(self): videos = [] try: r = self.session.get(self.host, timeout=15) r.encoding = 'utf-8' soup = BeautifulSoup(r.text, 'html.parser') cards = soup.select('div.relative.group a[href*="/dyrscom-"]') seen = set() for a in cards[:24]: href = a.get('href', '') if href in seen: continue seen.add(href) if not href.startswith('http'): href = urljoin(self.host, href) parent = a.find_parent('div', class_='relative') title = img_src = remark = '' if parent: h3 = parent.select_one('h3') if h3: title = h3.get_text(strip=True) img = parent.select_one('img[data-src]') if img: img_src = img.get('data-src', '') if img_src.startswith('/') and not img_src.startswith('//'): img_src = self.img_origin + img_src badge = parent.select_one('div.text-\\[10px\\].font-bold.absolute') if badge: remark = badge.get_text(strip=True) if title and href: videos.append({"vod_id": href, "vod_name": title, "vod_pic": img_src, "vod_remarks": remark}) except Exception as e: print(f"首页抓取失败: {e}") return videos # ===== 分类列表 ===== def categoryContent(self, tid, pg, filter, extend): pg = int(pg) if pg and str(pg).isdigit() else 1 class_param = extend.get('class', '') if extend else '' url = f"{self.host}/{tid}.html" if class_param: url += f"?class={quote(class_param)}" return self._parse_list(url, pg) def _parse_list(self, url, pg): videos = [] try: r = self.session.get(url, timeout=15) r.encoding = 'utf-8' soup = BeautifulSoup(r.text, 'html.parser') cards = soup.select('div.relative.group a[href*="/dyrscom-"]') for a in cards: href = a.get('href', '') if not href.startswith('http'): href = urljoin(self.host, href) parent = a.find_parent('div', class_='relative') title = img_src = remark = '' if parent: h3 = parent.select_one('h3') if h3: title = h3.get_text(strip=True) img = parent.select_one('img[data-src]') if img: img_src = img.get('data-src', '') if img_src.startswith('/') and not img_src.startswith('//'): img_src = self.img_origin + img_src badge = parent.select_one('div.text-\\[10px\\].font-bold.absolute') if badge: remark = badge.get_text(strip=True) if title and href: videos.append({"vod_id": href, "vod_name": title, "vod_pic": img_src, "vod_remarks": remark}) except Exception as e: print(f"列表抓取失败: {e}") return {"list": videos, "page": pg, "pagecount": pg+1 if len(videos)>=12 else pg, "limit": 24, "total": 9999} # ===== 详情页 (核心修复) ===== def detailContent(self, ids): vid = ids[0] if isinstance(ids, list) else ids if not vid.startswith('http'): vid = urljoin(self.host, vid) vod = {"vod_id": vid, "vod_name": "", "vod_pic": "", "vod_content": "", "vod_play_from": "电影人生", "vod_play_url": ""} try: r = self.session.get(vid, timeout=15) r.encoding = 'utf-8' html = r.text soup = BeautifulSoup(html, 'html.parser') # 标题/封面/简介 m = re.search(r'