源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-03-07 22:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python使用beautifulsoup从爱奇艺网抓取视频播放
[u]复制代码[/u] 代码如下:
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()
[img]http://files.jb51.net/file_images/article/201401/20140123091649.jpg?201402391758[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部