欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python3.6實(shí)現(xiàn)根據(jù)電影名稱(支持電視劇名稱),獲取下載鏈接的方法

 更新時(shí)間:2019年08月26日 09:00:32   作者:zhizunyu2009  
這篇文章主要介紹了Python3.6實(shí)現(xiàn)根據(jù)電影名稱(支持電視劇名稱),獲取下載鏈接的方法,涉及Python爬蟲與正則相關(guān)操作技巧,需要的朋友可以參考下

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

做個(gè)筆記
(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 = ['商品已售完','重復(fù)訂單','沒(méi)有騎手接單','聯(lián)系不上顧客','顧客需要重新下單']
  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
#訪問(wèn)url,返回html頁(yè)面
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):#根據(jù)電影名稱,生成搜索結(jié)果的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
#從搜索結(jié)果頁(yè)面,提取電影的詳情頁(yè)面鏈接,存入列表返回
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
#從電影詳情頁(yè)面中獲取電影標(biāo)題
def get_movie_title(html):
  soup=BeautifulSoup(html,'html.parser')
  fixed_html=soup.prettify()
  title=soup.find('h1')
  title=title.string
  return title
#從電影詳情頁(yè)面中獲取此頁(yè)面所有的的下載鏈接
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
#傳入電影列表,獲取每個(gè)電影的下載地址
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') #忽略編碼錯(cuò)誤
    m_title = get_movie_title(html)
    if u'游戲' not in m_title: #過(guò)濾游戲
      if u'動(dòng)畫' not in m_title: #過(guò)濾動(dòng)畫片
        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展現(xiàn)在頁(yè)面效果如下:

另一個(gè)網(wǎng)站的

# -*- 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 #關(guān)閉https協(xié)議驗(yàn)證證書
def get_html(url): #訪問(wèn)url,返回html頁(yè)面,如果url錯(cuò)誤,則返回狀態(tài)碼,一般是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):#根據(jù)電影名稱,返回正確的電影html
  pin = Pinyin()
  pinyin_movie_name = pin.get_pinyin(movie_name,"")#不使用分隔符,默認(rèn)是-
  movie_type = {
    "Sciencefiction":"科幻片",
    "Horror"    :"恐怖片",
    "Drama"     :"劇情片",
    "Action"    :"動(dòng)作片",
    "Comedy"    :"喜劇片",
    "Love"     :"愛(ài)情片",
    "War"      :"戰(zhàn)爭(zhēng)片"
  }
  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頁(yè)面中獲取下載地址
  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

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • python直接獲取API傳遞回來(lái)的參數(shù)方法

    python直接獲取API傳遞回來(lái)的參數(shù)方法

    今天小編就為大家分享一篇python直接獲取API傳遞回來(lái)的參數(shù)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • 40行Python代碼實(shí)現(xiàn)天氣預(yù)報(bào)和每日雞湯推送功能

    40行Python代碼實(shí)現(xiàn)天氣預(yù)報(bào)和每日雞湯推送功能

    這篇文章主要介紹了通過(guò)40行Python代碼實(shí)現(xiàn)天氣預(yù)報(bào)和每日雞湯推送功能,代碼簡(jiǎn)單易懂,非常不錯(cuò)具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2020-02-02
  • 如何通過(guò)50行Python代碼獲取公眾號(hào)全部文章

    如何通過(guò)50行Python代碼獲取公眾號(hào)全部文章

    這篇文章主要介紹了如何通過(guò)50行Python代碼獲取公眾號(hào)全部文章,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Python讀取Excel數(shù)據(jù)實(shí)現(xiàn)批量生成PPT

    Python讀取Excel數(shù)據(jù)實(shí)現(xiàn)批量生成PPT

    我們常常面臨著大量的重復(fù)性工作,通過(guò)人工方式處理往往耗時(shí)耗力易出錯(cuò)。而Python在辦公自動(dòng)化方面具有天然優(yōu)勢(shì)。本文將利用讀取Excel數(shù)據(jù)并實(shí)現(xiàn)批量生成PPT,需要的可以參考一下
    2022-05-05
  • python?操作?mongodb?數(shù)據(jù)庫(kù)詳情

    python?操作?mongodb?數(shù)據(jù)庫(kù)詳情

    這篇文章主要介紹了python?操作?mongodb?數(shù)據(jù)庫(kù)詳情,通過(guò)鏈接數(shù)據(jù)庫(kù),創(chuàng)建數(shù)據(jù)庫(kù)展開(kāi)內(nèi)容詳細(xì),具有一定的參考價(jià)值,需要的的小伙伴可以參考一下
    2022-04-04
  • Python大數(shù)據(jù)之網(wǎng)絡(luò)爬蟲的post請(qǐng)求、get請(qǐng)求區(qū)別實(shí)例分析

    Python大數(shù)據(jù)之網(wǎng)絡(luò)爬蟲的post請(qǐng)求、get請(qǐng)求區(qū)別實(shí)例分析

    這篇文章主要介紹了Python大數(shù)據(jù)之網(wǎng)絡(luò)爬蟲的post請(qǐng)求、get請(qǐng)求區(qū)別,結(jié)合具體實(shí)例形式分析了Python網(wǎng)頁(yè)爬蟲post請(qǐng)求與get請(qǐng)求相關(guān)使用技巧,需要的朋友可以參考下
    2019-11-11
  • Python編程快速上手——Excel表格創(chuàng)建乘法表案例分析

    Python編程快速上手——Excel表格創(chuàng)建乘法表案例分析

    這篇文章主要介紹了Python Excel表格創(chuàng)建乘法表,結(jié)合具體實(shí)例形式分析了Python接受cmd命令操作Excel文件創(chuàng)建乘法表相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2020-02-02
  • python中count函數(shù)簡(jiǎn)單用法

    python中count函數(shù)簡(jiǎn)單用法

    在本篇文章里小編給大家整理的是一篇關(guān)于python中count函數(shù)簡(jiǎn)單用法以及相關(guān)實(shí)例,需要的朋友們學(xué)習(xí)下。
    2020-01-01
  • pandas map(),apply(),applymap()區(qū)別解析

    pandas map(),apply(),applymap()區(qū)別解析

    這篇文章主要介紹了pandas map(),apply(),applymap()區(qū)別解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Python學(xué)習(xí)筆記之函數(shù)的參數(shù)和返回值的使用

    Python學(xué)習(xí)筆記之函數(shù)的參數(shù)和返回值的使用

    這篇文章主要介紹了Python學(xué)習(xí)筆記之函數(shù)的參數(shù)和返回值的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評(píng)論