In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how Python can capture all Tencent Video's movies". In daily operation, I believe many people have doubts about how Python can capture all Tencent Video's films. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve Python to capture all Tencent Video's movies". Next, please follow the editor to study!
Operation environment
IDE, pycharm
Version (Python3.6)
System, Windows
Achieve the goal and train of thought purpose
To achieve the parsing and downloading of Tencent Video's target url, due to third-party vip parsing, only online viewing is provided, and you want to download the target video.
Train of thought
First of all, get the Tencent movie url you want to see, parse it through a third-party vip video parsing website, grab the package, simulate the browser to send a normal request, get the cache ts file, download the video ts file, and finally convert it to a mp4 file to achieve normal playback.
Complete code import reimport os,shutilimport requests,threadingfrom urllib.request import urlretrievefrom pyquery import PyQuery as pqfrom multiprocessing import Pool'class video_down (): def _ _ init__ (self Url): # splicing universal resolution url self.api=' https://jx.618g.com' self.get_url = 'https://jx.618g.com/?url=' + url # set up UA simulation browser access self.head = {' User-Agent': 'Mozilla/5.0 (Windows NT 6.1) WOW64) AppleWebKit/537.36 (KHTML Like Gecko) Chrome/63.0.3239.132 Safari/537.36'} # set the number of multithreads self.thread_num=32 # number of files currently downloaded self.i = 0 # call the web page to get html = self.get_page (self.get_url) if html: # parse the web page Self.parse_page (html) def get_page (self Get_url): try: print ('requesting target page....', get_url) response=requests.get (get_url,headers=self.head) if response.status_code==200: # print (response.text) print ('request target page completed.\ nprepare to parse....') Self.head ['referer'] = get_url return response.text except Exception: print (' failed to request the target web page, please check for errors and try again') return None def parse_page (self,html): print ('target information is being parsed.') Doc=pq (html) self.title=doc ('head title'). Text () print (self.title) url = doc (' # player'). Attr ('src') [14:] html=self.get_m3u8_1 (url). Strip () # self.url = url +' 800klap hlsindex.m3u8' self.url = url [:-10] + html print (self.url) print ('parsing complete Get the cache ts file.') Self.get_m3u8_2 (self.url) def get_m3u8_1 (self,url): try: response=requests.get (url,headers=self.head) html=response.text print ('obtained ts file successfully, ready to extract information') return html [- 20:] except Exception: print ('cache file request error 1 Please check for errors') def get_m3u8_2 (self,url): try: response=requests.get (url,headers=self.head) html=response.text print ('ts file obtained successfully, ready to extract information') self.parse_ts_2 (html) except Exception: print ('cache file request error 2 Please check for errors') def parse_ts_2 (self,html): pattern=re.compile ('. *? (. *?). Ts') self.ts_lists=re.findall (pattern,html) print ('information extraction completed.\ nready for download.') Self.pool () def pool (self): print ('calculated to download% d files'% len (self.ts_lists)) self.ts_url = self.url [:-10] if self.title not in os.listdir (): os.makedirs (self.title) print ('downloading... It takes a long time Please wait patiently..) # start multiple processes to download pool=Pool (16) pool.map (self.save_ts) [ts_list for ts_list in self.ts_lists]) pool.close () pool.join () print ('download complete') self.ts_to_mp4 () def ts_to_mp4 (self): print ('ts file is transcribing mp4.') Str='copy / b'+ self.title+'\ * .ts'+ self.title+'.mp4' os.system (str) filename=self.title+'.mp4' if os.path.isfile (filename): print ('conversion complete Enjoy your viewing of the movie') shutil.rmtree (self.title) def save_ts (self,ts_list): try: ts_urls = self.ts_url +'{} .ts' .format (ts_list) self.i + = 1 print ('current progress% dash% dink% (self.i,len (self.ts_lists) urlretrieve (url=ts_urls) Filename=self.title +'/ {} .ts' .format (ts_list) except Exception: print ('error in saving file') if _ _ name__ = ='_ _ main__': # Movie Target url: the four Kings of Di Renjie, url=' https://v.qq.com/x/cover/r6ri9qkcu66dna8.html' # Mission impossible 5: mysterious country url1='https:/ / v.qq.com url2=' https://v.qq.com/x/cover/lcpwn26degwm7t3/z0027injhcq.html' url3=' https://v.qq.com/x/cover/33bfp8mmgakf0gi.html' video_down (url2) video cache ts file
Here are some cached video files, each with only a few seconds to play, and finally need to be merged into a video in mp4 format, which can be played normally. The default HD download
Note that the progress here is for reference only because of the use of multi-process downloads, and there is no exact display of the progress. You can go to the folder to check the normal progress, which can be understood as displaying the progress once and downloading a ts file.
Realize the effect
At this point, the study on "how to capture all Tencent Video's movies by Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.