python使用beautifulsoup從愛(ài)奇藝網(wǎng)抓取視頻播放
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使用方法詳解
- Python BeautifulSoup中文亂碼問(wèn)題的2種解決方法
- python 解析html之BeautifulSoup
- python中bs4.BeautifulSoup的基本用法
- python基于BeautifulSoup實(shí)現(xiàn)抓取網(wǎng)頁(yè)指定內(nèi)容的方法
- python利用beautifulSoup實(shí)現(xiàn)爬蟲(chóng)
- python爬蟲(chóng)之BeautifulSoup 使用select方法詳解
- Python爬蟲(chóng)之BeautifulSoup的基本使用教程
相關(guān)文章
在Mac OS系統(tǒng)上安裝Python的Pillow庫(kù)的教程
這篇文章主要介紹了在MacOS下安裝Python的Pillow庫(kù)的教程,Pillow庫(kù)用來(lái)對(duì)圖片進(jìn)行各種處理操作,需要的朋友可以參考下2015-11-11
解決python3報(bào)錯(cuò)之takes?1?positional?argument?but?2?were?gi
這篇文章主要介紹了解決python3報(bào)錯(cuò)之takes?1?positional?argument?but?2?were?given問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
Python tkinter實(shí)現(xiàn)簡(jiǎn)單加法計(jì)算器代碼實(shí)例
這篇文章主要介紹了Python tkinter實(shí)現(xiàn)簡(jiǎn)單加法計(jì)算器代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
用django-allauth實(shí)現(xiàn)第三方登錄的示例代碼
這篇文章主要介紹了用django-allauth實(shí)現(xiàn)第三方登錄的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-06-06
python獲取酷狗音樂(lè)top500的下載地址 MP3格式
這篇文章主要介紹了python獲取酷狗音樂(lè)top500的下載地址 MP3格式,文中給大家提到了python--爬取酷狗TOP500的數(shù)據(jù),需要的朋友可以參考下2018-04-04
詳談python3 numpy-loadtxt的編碼問(wèn)題
下面小編就為大家分享一篇詳談python3 numpy-loadtxt的編碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-04-04

