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

yipeiwu_com6年前Python爬虫

复制代码 代码如下:

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正则爬取某段子网站前20页段子(request库)过程解析

python正则爬取某段子网站前20页段子(request库)过程解析

首先还是谷歌浏览器抓包对该网站数据进行分析,结果如下: 该网站地址:http://www.budejie.com/text 该网站数据都是通过html页面进行展示,网站url默认为第...

Python开发实例分享bt种子爬虫程序和种子解析

看到网上也有开源的代码,这不,我拿来进行了二次重写,呵呵,上代码:  #encoding: utf-8     &n...

python requests库爬取豆瓣电视剧数据并保存到本地详解

python requests库爬取豆瓣电视剧数据并保存到本地详解

首先要做的就是去豆瓣网找对应的接口,这里就不赘述了,谷歌浏览器抓包即可,然后要做的就是分析返回的json数据的结构: https://movie.douban.com/j/search...

Python实现的爬虫刷回复功能示例

Python实现的爬虫刷回复功能示例

本文实例讲述了Python实现的爬虫刷回复功能。分享给大家供大家参考,具体如下: 最近闲的无聊,就想着去看看爬虫,顺着爬虫顺利的做到了模拟登录、刷帖子等等,这里简要说一下。 使用Pyth...

python爬取个性签名的方法

本文实例为大家分享了python爬取个性签名的具体代码,具体内容如下 #coding:utf-8 #import tkinter from tkinter import * from...