python使用beautifulsoup從愛奇藝網(wǎng)抓取視頻播放
import sys
import urllib
from urllib import request
import os
from bs4 import BeautifulSoup
class DramaItem:
def __init__(self, num, title, url):
self.num = num
self.title = title
self.url = url
def __str__(self):
return self.num + ' ' + self.title
def openDrama(self):
os.startfile(self.url)
response = urllib.request.urlopen('http://www.iqiyi.com/a_19rrgja8xd.html')
html = response.read()
soup = BeautifulSoup(html)
dramaList = soup.findAll('div', attrs={'class':'list_block1 align_c'})
dramaItems = []
if(dramaList):
lis = dramaList[0].findAll('li')
for li in lis:
ps = li.findAll('p')
description = ps[1].text if len(ps)>1 else ''
num = ps[0].find('a').text
url = ps[0].find('a')['href']
di = DramaItem(num, description, url)
dramaItems.append(di)
for di in dramaItems:
print(di)
diLen = len(dramaItems)
userChoice = int(input('input number to watch the drama:'))
if userChoice >= 1 and userChoice <=diLen:
dramaItems[userChoice-1].openDrama()

相關(guān)文章
Python 實(shí)現(xiàn)繪制子圖及子圖刻度的變換等問題
這篇文章主要介紹了Python 實(shí)現(xiàn)繪制子圖及子圖刻度的變換等問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05anaconda虛擬環(huán)境python?sklearn庫(kù)的安裝過程
Anaconda是專注于數(shù)據(jù)分析的Python發(fā)行版本,包含了conda、Python等190多個(gè)科學(xué)包及其依賴項(xiàng),這篇文章主要給大家介紹了關(guān)于anaconda虛擬環(huán)境python?sklearn庫(kù)的安裝過程,需要的朋友可以參考下2023-11-11Python:Scrapy框架中Item Pipeline組件使用詳解
這篇文章主要介紹了Python:Scrapy框架中Item Pipeline組件使用詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下2017-12-12selenium+python自動(dòng)化測(cè)試之使用webdriver操作瀏覽器的方法
這篇文章主要介紹了selenium+python自動(dòng)化測(cè)試之使用webdriver操作瀏覽器的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01Python數(shù)據(jù)類型之String字符串實(shí)例詳解
這篇文章主要介紹了Python數(shù)據(jù)類型之String字符串,結(jié)合實(shí)例形式詳細(xì)講解了Python字符串的概念、定義、連接、格式化、轉(zhuǎn)換、查找、截取、判斷等常見操作技巧,需要的朋友可以參考下2019-05-05python神經(jīng)網(wǎng)絡(luò)使用Keras構(gòu)建RNN訓(xùn)練
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)使用Keras構(gòu)建RNN網(wǎng)絡(luò)訓(xùn)練,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>2022-05-05