Copy Code code as follows:
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 ()