python-爬取中国评书网音频

1.打开http://www.zgpingshu.com/

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()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值