python使用beautifulsoup从爱奇艺网抓取视频播放

时间:2021-07-29 01:10:42 


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使用beautifulsoup从爱奇艺网抓取视频播放

标签:beautifulsoup,爱奇艺网
0
投稿

猜你喜欢

  • python基于phantomjs实现导入图片

    2023-07-18 23:39:42
  • asp访google分页代码

    2009-07-10 13:06:00
  • Python paramiko 模块浅谈与SSH主要功能模拟解析

    2023-10-01 11:06:28
  • 简单介绍Python中的struct模块

    2023-09-22 16:27:01
  • python使用Image处理图片常用技巧分析

    2023-01-17 14:51:38
  • ASP可显示和隐藏的树型菜单

    2007-10-01 14:40:00
  • 浅谈Django 页面缓存的cache_key是如何生成的

    2022-03-20 09:53:02
  • 三达不溜:www

    2009-03-28 11:44:00
  • JS数组方法汇总

    2009-08-03 14:06:00
  • SQL Server应用程序的高级Sql注入

    2009-04-11 16:54:00
  • Python创建简单的神经网络实例讲解

    2021-12-02 05:38:41
  • python中list常用操作实例详解

    2021-05-13 02:33:25
  • python如何实现int函数的方法示例

    2022-06-02 08:37:38
  • python高阶函数functools模块的具体使用

    2022-12-08 09:03:15
  • python3实现带多张图片、附件的邮件发送

    2023-05-11 06:51:10
  • 用asp编写文档搜索页面

    2008-01-13 07:04:00
  • snoopy PHP版的网络客户端提供本地下载

    2023-06-28 00:09:55
  • Python可视化神器pyecharts之绘制箱形图

    2021-08-04 03:40:53
  • python处理PHP数组文本文件实例

    2023-11-09 23:56:03
  • swoole和websocket简单聊天室开发

    2023-10-23 07:20:24
  • asp之家 网络编程 m.aspxhome.com