2.随便选一本,点击下载按钮
3.打开页面后,f12打开,看里层的download按钮绑定的id
4.最后,代码供上:
# -*- coding: utf-8 -*-
import time
import SendKeys
import requests
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
class TestDownMp3Controller():
def bbb(self):
webDriver_self = webdriver.Firefox(executable_path='F:\software\geckodriver-v0.23.0-win64\geckodriver.exe')
webDriver_self.maximize_window()
count = 14
while (count < 20):
print 'The count is:', count
html = 'http://www.zgpingshu.com/down/3825/' + str(count) + '.html'
print html
webDriver_self.get(html)
time.sleep(1)
element = WebDriverWait(webDriver_self, 10, 0.5).until(
EC.presence_of_element_located((By.XPATH, '//a[@id="down"]')))
link = webDriver_self.find_element_by_xpath('//a[@id="down"]')
url = link.get_attribute('href')
name = webDriver_self.find_element_by_xpath('//a[@id="down"]/img').get_attribute('alt')[9:]
print "请求地址:",url
print "名字:",name
response = requests.get(url).content
f = open(u'G:\\音乐\\评书\\希腊神话\\'+name+'.mp3','wb')
f.write(response)
f.close()
count = count+1
a = TestDownMp3Controller()
a.bbb()