zoukankan      html  css  js  c++  java
  • python2.7 selenium chromedriver 下载抖音无水印短视频

    python code
    --------------------------------------------------------------------------------
    # coding=utf-8
    
    from selenium import webdriver
    import time, re, os, sys
    reload(sys)
    sys.setdefaultencoding("utf-8")
    
    if len(sys.argv)==1:
        print 'input url'
        sys.exit()
    url = sys.argv[1]
    
    def main():
        options = webdriver.ChromeOptions()
        options.headless = True
        options.add_argument('log-level=3')
        options.add_experimental_option('excludeSwitches', ['enable-logging'])
        options.add_argument('user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25')
    
        chrome_driver = 'D:softChromePortable81.0.4044.92AppChrome-binchromedriver.exe'
        b = webdriver.Chrome(executable_path = chrome_driver,options=options)
        print 'Downloading page ...'
        b.get(url)
        time.sleep(1)
        page_source = b.page_source
        b.quit()
    
        src = re.findall( r'<video id="theVideo" class="video-player" src="(.*?)"', page_source,  re.S)
        if src:
            src = "".join(src)
            print src
            src2 = src.replace('playwm','play')
            print src2
        else:
            print "No match src"
        userTitle = re.findall( r'<div class="user-title">(.*?)</div>', page_source,  re.S)
        if userTitle:
            userTitle = "".join(userTitle)
            print userTitle
        else:
            print "No match user Title"
        name = re.findall( r'<p class="user-info-name">(.*?)</p>', page_source,  re.S)
        if name:
            name = "".join(name)
            name = name.replace('@','')
            print name
        else:
            print "No match name"
        uid = re.findall( r'<p class="user-info-id">(.*?)</p>', page_source,  re.S)
        if uid:
            uid = "".join(uid)
            uid = uid.replace('抖音ID:','')
            uid = uid.replace(' ','')
            print uid
        else:
            print "No match uid"
    
        print "downloading video with wget"
        cmd = 'wget "'+ src2 + '" -O "' + uid + '_' + name+'.mp4"'
        cmd = cmd.decode('utf8').encode('gb2312')
        val = os.system(cmd)
        print val
    
    if __name__ == '__main__':
        main()
    
    --------------------------------------------------------------------------------
    batch file
    --------------------------------------------------------------------------------
    @echo off
    chcp 936 1>nul 2>nul
    D:Python27python.exe D:\_progpydownload_douyin_video.py %*
     
  • 相关阅读:
    [转]jquery开发自定义的插件总结
    [转]net中哈希表的使用 Hashtable
    [转]C#编程总结(三)线程同步
    [转]大白话系列之C#委托与事件讲解(三)
    [书目20160706]成功销售实用经典10步骤(美国培训与发展协会实用经典10步系列)
    [转]backbone.js template()函数
    [转]ASP.NET MVC Dynamic Themes
    [转]C#网络编程(订立协议和发送文件)
    [转]C#网络编程(异步传输字符串)
    [转]C#网络编程(同步传输字符串)
  • 原文地址:https://www.cnblogs.com/nlsoft/p/13237484.html
Copyright © 2011-2022 走看看