Python uses BeautifulSoup to crawl video playback from the Archie Art network _python

Source: Internet
Author: User

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 ()



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.