python使用beautifulsoup從愛奇藝網抓取視頻播放
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()

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