1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
import re import urllib3 import os from selenium import webdriver
from multiprocessing import Pool from time import time from time import sleep
def mkdir(path): isExists = os.path.exists(path) if not isExists: os.makedirs(path)
def getPageData(link): http = urllib3.PoolManager( num_pools=5, headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36' } ) res = http.request('GET', link) return res.data
def main(name, save_url): print('开始下载:',name, link, save_url) res = getPageData(link).decode('gbk') download_url1 = re.findall('datas=(.*?)&mp3', res) download_url2 = re.findall('http(.*?)mp3&', download_url1[0]) res = getPageData("http" + download_url2[0] + "mp3") with open(save_url + name + '.mp3', 'wb') as code: code.write(res) print(save_url + name + ' 下载完成!',time.strftime('%Y.%m.%d',time.localtime(time.time())))
def init(url, max_pages): arr_pages = [] for n in range(0, max_pages): arr_pages.append(url + str(n + 1) + '.html') return arr_pages
save_url = '/有声小说/大主宰/' main_url = 'https://ting55.com/book/10797-159'
driver = webdriver.Chrome(r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
driver.get(main_url)
id = driver.find_element_by_css_selector("#jp_audio_0") print(id)
driver.quit()
|