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()
标签:beautifulsoup,爱奇艺网
0
投稿
猜你喜欢
jdbc操作mysql数据库实例
2024-01-26 01:59:50
Python函数参数定义及传递方式解析
2021-10-19 21:28:25
MySQL密码忘了怎么办?MySQL重置root密码方法
2024-01-23 02:18:30
vue.js2.0 实现better-scroll的滚动效果实例详解
2023-07-02 16:58:50
用一条mysql语句插入多条数据
2024-01-18 16:35:40
CentOS下安装Jenkins的完整步骤
2022-12-13 16:43:34
Python实现小黑屋游戏的完整实例
2021-03-08 13:27:43
浅谈python类属性的访问、设置和删除方法
2022-01-12 00:14:48
sql server删除前1000行数据的方法实例
2024-01-18 14:47:39
python绘制漏斗图步骤详解
2021-06-17 22:57:57
Vue mock.js模拟数据实现首页导航与左侧菜单功能
2024-05-09 09:51:57
MySQL binlog_ignore_db 参数的具体使用
2024-01-20 12:32:59
mysql中如何查看表空间
2024-01-27 00:25:25
python中pandas对多列进行分组统计的实现
2022-06-25 03:50:03
javascript页面上使用动态时间具体实现
2024-05-11 09:36:06
怎样在JavaScript里写一个swing把数据插入数据库
2024-01-20 09:26:42
Ubuntu下mysql与mysql workbench安装教程
2024-01-14 23:08:40
Google中秋logo被恶搞
2007-09-25 15:55:00
Python获取当前公网ip并自动断开宽带连接实例代码
2021-08-28 12:40:27
Django 源码WSGI剖析过程详解
2023-09-14 22:19:58