国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用beautifulsoup從愛奇藝網(wǎng)抓取視頻播放

2019-11-25 18:33:14
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

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()



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 房山区| 肇东市| 阜平县| 南郑县| 镇雄县| 五常市| 赤水市| 泰兴市| 江门市| 红桥区| 通化市| 安义县| 水富县| 陈巴尔虎旗| 都匀市| 松潘县| 信丰县| 巴彦淖尔市| 抚顺市| 都江堰市| 日土县| 固原市| 合山市| 兴安盟| 霍城县| 山东省| 临猗县| 漳平市| 四子王旗| 汝阳县| 南华县| 东源县| 邛崃市| 六安市| 葫芦岛市| 禄丰县| 吴旗县| 长治县| 汝城县| 子长县| 巴青县|