Download Link: http://www.pearvideo.com/category_1
ImportRequests fromlxmlImportetreeImportRe fromUrllib.requestImportUrlretrieve" "1 Get video id2 stitching complete url3 get full video playback address 4 download video" "defdownload_video (URL):#url = ' http://www.pearvideo.com/category_1 'Response = requests.get (URL)#returns status Code 200, representing the request successHTML =Response.text#to process a text file into a resolvable objectHTML =etree. HTML (HTML)#get the video IDvideo_id = Html.xpath ("//div[@class = ' vervideo-bd ']/a/@href") StartURL="http://www.pearvideo.com" #video playback URL listVideo_urls = [] forIinchVideo_id:newurl= StartURL +'/'+i video_urls.append (newurl) forUrlinchvideo_urls:html=requests.get (URL). Text#get video playback real address #Regular expression pattern that defines the playback address #Srcurl = "Http://video.pearvideo.com/mp4/adshort/20180720/cont-1393622-12502013_adpkg-ad_hd.mp4"req ='srcurl= "(. *?)"' #compiles a regular expression string as an object, which is designed to improve efficiency and can bereq =re.compile (req) Play_url= Re.findall (req, HTML)#Note that the Play_url format is List #Get video title #defining the video title regular expression pattern #Re_tag ='
'Tag=Re.findall (Re_tag, HTML)#Download Video Print("Downloading%s"%tag[0]) Urlretrieve (play_url[0],"./video/{}.mp4". Format (tag[0]))#print ("Download complete%s"%tag[0])#Download_video ()#dynamically loading link changes#http://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=1&start=12&mrd= 0.8960730781029713&hotcontids=1394290,1394224,1394233#http://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=1&start=24&mrd= 0.45490116190392094&hotcontids=1394290,1394224,1394233http://www.pearvideo.com/category_loading.jsp? reqtype=5&categoryid=1&start=24&mrd=0.45490116190392094&hotcontids=1394290,1394224,1394233 #http://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=1&start=36&mrd= 0.895263612547242&hotcontids=1394290,1394224,1394233#&MRD The back of the thing can not be added#Dynamic load DownloaddefDownload_more (): N= 12 whileTrue:ifn > 48: return #or break jump out of the loopURL ="http://www.pearvideo.com/category_loading.jsp?reqType=5&categoryId=1&start=%d"%n download_video (URL) n+ = 12#Sleep (Ten)Download_more ()
F12 Open Developer Tools, NetWork--Find the Request URL, Headers, category_loading, beginning with dynamically loading HTML entries
Python dynamically loads and downloads "pear video" short video