爬取某電影網站(未寫完)


  1 import requests
  2 import bs4
  3 import lxml
  4 import re
  5 import time
  6 from bs4 import BeautifulSoup
  7 #網站
  8 url = 'https://www.88ys.cc'
  9 #電影或電視劇的名字
 10 film = '家有女友'
 11 #代理ip
 12 proxy='120.24.245.33:16818'#已過期,需續費
 13 proxies = {
 14     'http':'http://'+proxy,
 15     'https':'https://'+proxy
 16     }
 17 #gzip訪問速度更快
 18 headers = {
 19     "Accept-Encoding": "gzip"
 20     }
 21 ####搜索結果####
 22 def search():
 23     ####搜索結果####
 24     #搜索鏈接
 25     url_search = url + '/index.php?m=vod-search'
 26     #post需要提交的參數
 27     data = {
 28         'wd':film ,
 29         'submit':''
 30     }
 31     #提交搜索內容的表單
 32     #①無代理
 33     r_s = requests.post(url_search, data=data)
 34     #②有代理
 35     # r_s = requests.post(url_search, data=data, proxies=proxies, headers=headers)
 36     #設置編碼
 37     r_s.encoding = 'utf-8'
 38     #接收返回的網頁
 39     text_s = r_s.text
 40     #
 41     pat = re.compile(r'<a class="link-hover" href="(.*?)"')
 42     pat_is = re.findall(pat, text_s)
 43     # print(pat_is)
 44     return pat_is
 45 ####獲取集數####
 46 def List(pat_search):
 47     ####獲取集數####
 48     #搜索結果鏈接
 49     url_list = url + pat_search
 50     #打開合並的鏈接
 51     # r_list = requests.get(url_list, proxies=proxies, headers=headers)
 52     r_list = requests.get(url_list)
 53     #設置字符編碼
 54     r_list.encoding = 'utf-8'
 55     #接收鏈接網頁
 56     text_list = r_list.text
 57     # print(text_list)
 58     #使用BeautifulSoup獲取第一個片源的所有集數鏈接
 59     text_l_b = BeautifulSoup(text_list,'lxml')
 60     stab81 = text_l_b.find_all(name='div', attrs={'id':'stab81'})
 61     stab81_re = re.findall(re.compile(r'href="(.*?)"'), str(stab81[0]))
 62     # print(stab81_re)
 63     return stab81_re
 64 ####搜索結果文字信息####
 65 def search_news(pat_search):
 66     ####搜索結果文字信息####
 67     #存儲獲取的信息以集合形式返回
 68     #[0]電影名[1]影片類型[2]語言
 69     information = []
 70     #建立連接
 71     url_search = url + pat_search
 72     r = requests.get(url_search)
 73     #設置編碼
 74     r.encoding = 'utf-8'
 75     #獲取電影信息的div
 76     bs = str(BeautifulSoup(r.text, 'lxml').find_all('div', class_='ct-c'))
 77     #獲取電影名稱,並添加到集合
 78     h1_bs = BeautifulSoup(bs,'lxml')
 79     h1_re = re.findall(re.compile(r'>(.*?)<'), str(h1_bs.h1))
 80     information.append(h1_re[0])
 81     #類型
 82     type_re = re.findall(re.compile(r'類型:</span>(.*?)</dd>'), bs)
 83     information.append(type_re[0])
 84     #語言
 85     language_re = re.findall(re.compile(r'語言:</span>(.*?)</dd>'), bs)
 86     information.append(language_re[0])
 87     # print(information)
 88     return information
 89 ####Main函數(循環獲取搜索結果和集數)####
 90 def _for_():
 91     ####循環獲取搜索結果和集數####
 92     #調用搜索
 93     pat_search = search()
 94     #接收影片返回信息
 95     information = None
 96     #接收片源一返回的信息
 97     stab81 = None
 98     # 循環調用方法
 99     for i in pat_search:
100         #調用方法並接收
101         information = search_news(i)
102         #調用方法並接收
103         stab81 = List(i)
104         #打印
105         print(information)
106         #打印
107         print(stab81)
108         #使用延時防止運行太快被網站強制斷開連接
109         time.sleep(3)
110 # 調用主(Main)函數
111 _for_()
112 ####未做完,查看器和爬取源碼不一致####
113 def a():
114     _url_ = url + '/vod-play-id-56106-src-1-num-1.html'
115     r = requests.get(_url_)
116     r.encoding = 'utf-8'
117     bs = BeautifulSoup(r.text,'lxml')
118     print(bs.prettify())

(未解決問題)

1.查看器和爬取源碼不一致

2.獲取視頻鏈接

3.電影下載操作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM