日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python下电影_Python3.6实现根据电影名称(支持电视剧名称),获取下载链接的方法...

發布時間:2023/12/10 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python下电影_Python3.6实现根据电影名称(支持电视剧名称),获取下载链接的方法... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了Python3.6實現根據電影名稱(支持電視劇名稱),獲取下載鏈接的方法。分享給大家供大家參考,具體如下:

做個筆記

(python 3.6,django 2.0)

def get_url(outer_order_id):

refundId = get_refundId(outer_order_id)

host_url = 'http://test.shequ.com/order/agreeRefund?'

reason_list = ['商品已售完','重復訂單','沒有騎手接單','聯系不上顧客','顧客需要重新下單']

reason = random.choice(reason_list)

api_data = {

'reason':reason,

'refundId':refundId,

'sendType':0

}

url = host_url + parse.urlencode(api_data)

return url

print(get_url('3086123456'))

http://test.shequ.com/order/agreeRefund?reason=%E9%87%8D%E5%A4%8D%E8%AE%A2%E5%8D%95&refundId=1170611&sendType=0

# -*- coding: utf-8 -*-

import urllib

from bs4 import BeautifulSoup

import re

#訪問url,返回html頁面

def get_html(url):

req = urllib.request.Request(url)

req.add_header('User-Agent','Mozilla/5.0')

response = urllib.request.urlopen(url)

html = response.read()

return html

def get_movie_url(movie_name):#根據電影名稱,生成搜索結果的URL

host_url = 'http://s.dydytt.net/plus/search.php?kwtype=0&keyword='

movie_sign = urllib.parse.quote(movie_name.encode('GBK'))

search_url = host_url + movie_sign

return search_url

#從搜索結果頁面,提取電影的詳情頁面鏈接,存入列表返回

def get_movie_list(url):

m_list = []

html = get_html(url)

soup = BeautifulSoup(html,'html.parser')

fixed_html = soup.prettify()

a_urls = soup.find_all('a')

host = "http://www.ygdy8.com"

for a_url in a_urls:

m_url = a_url.get('href')

m_url = str(m_url)

if re.search(r'\d{8}',m_url) and (host not in m_url):

m_list.append(host + m_url)

return m_list

#從電影詳情頁面中獲取電影標題

def get_movie_title(html):

soup=BeautifulSoup(html,'html.parser')

fixed_html=soup.prettify()

title=soup.find('h1')

title=title.string

return title

#從電影詳情頁面中獲取此頁面所有的的下載鏈接

def get_movie_download_url(html):

soup = BeautifulSoup(html,'html.parser')

fixed_html = soup.prettify()

td = soup.find_all('td',attrs={'style':'WORD-WRAP: break-word'})

down_urls = []

for t in td:

down_urls.append(t.a.get('href'))

return down_urls

#傳入電影列表,獲取每個電影的下載地址

def get_movie(movie_list):

movie_dict = {}

for i in range(0,len(movie_list)):

html = get_html(movie_list[i])

html = html.decode('GBK','ignore') #忽略編碼錯誤

m_title = get_movie_title(html)

if u'游戲' not in m_title: #過濾游戲

if u'動畫' not in m_title: #過濾動畫片

m_url_list = get_movie_download_url(html)

for m_url in m_url_list:

movie_dict[m_url] = m_title

return movie_dict

用django展現在頁面效果如下:

另一個網站的

# -*- coding: utf-8 -*-

from xpinyin import Pinyin

from bs4 import BeautifulSoup

from urllib import request,error

import time,re

import ssl

ssl._create_default_https_context = ssl._create_unverified_context #關閉https協議驗證證書

def get_html(url): #訪問url,返回html頁面,如果url錯誤,則返回狀態碼,一般是404

req = request.Request(url)

req.add_header('User-Agent','Mozilla/5.0')

try:

response = request.urlopen(url)

html = response.read()

return html

except error.HTTPError as e:

return e.code

def get_m_html(movie_name):#根據電影名稱,返回正確的電影html

pin = Pinyin()

pinyin_movie_name = pin.get_pinyin(movie_name,"")#不使用分隔符,默認是-

movie_type = {

"Sciencefiction":"科幻片",

"Horror" :"恐怖片",

"Drama" :"劇情片",

"Action" :"動作片",

"Comedy" :"喜劇片",

"Love" :"愛情片",

"War" :"戰爭片"

}

host = "https://www.kankanwu.com"

for k,v in movie_type.items():

movie_url = host + "/" + k + "/" + pinyin_movie_name + "/"

html = get_html(movie_url)

if isinstance(html,int):

time.sleep(10)

else:

return html

def get_dload_url(html): #從電影html頁面中獲取下載地址

movie_dict = {}

soup = BeautifulSoup(html,'lxml')

fixed_html = soup.prettify()

a_urls = soup.find_all(href=re.compile("thunder"))#找到含有thunder鏈接的href

for url in a_urls:

m_title = url.get('title')

m_url = url.get('href')

movie_dict[m_title] = m_url

return movie_dict

希望本文所述對大家Python程序設計有所幫助。

總結

以上是生活随笔為你收集整理的python下电影_Python3.6实现根据电影名称(支持电视剧名称),获取下载链接的方法...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。