#coding = utf-8
import requests
import pandas as pd
import os,time root_path = './根目录/'
input_file = '码表.xlsx'
url = 'http://api.map.baidu.com/geocoder/v2/?id = %s&local=1'
fail_file = root_path +'fail.csv' class Auto_down:
def __init__(self):
print("--start--")
def read_excel(self):
# pd.read_excel(converters = {u'列名':str})按照str类型读入,不会出现0被舍去的情况
sheet = pd.read_excel(input_file,converters = {u'列名':str},sheetname = '子表名')
cust_Id = sheet['cust_id']
void_Id = sheet['void_id'] for i in range(len(cust_Id)):
self.create_file(cust_Id[i],void_Id[i]) def download_voice(self,custid_filename,voiceid):
print(voiceid)
try:
r = requests.get(url%voiceid)
return_code = r.status_code
if return_code == 200:
voice_filename = '%s/%s.mp3'%(custid_filename,voiceid)
with open(voice_filename, 'wb') as fd:
fd.write(r.content)
else:
with open(fail_file, 'a+') as ff:
ff.write(voiceid + '\n')
except:
print('request url is fail!!')
with open(fail_file, 'a+') as ff:
ff.write(voiceid + '\n') def create_file(self, custid, voiceid):
custid_filename = root_path + custid
if not os.path.exists(custid_filename):
os.mkdir(custid_filename)
else:
self.download_voice(custid_filename,voiceid) if __name__ == '__main__':
tStart = time.clock() AD = Auto_down()
AD.read_excel() tEnd = time.clock() print("%s s"%(tEnd - tStart))
#coding = utf-8
import requests root_path = "./下载/" url = ""
fail_file = root_path + 'fail.csv'
voiceid = ''
for i in range(3):
try:
r = requests.get(url)
return_code = r.status_code
if r.status_code == 200:
voice_filename = root_path + 'dada.fdf'
with open(voice_filename,'wb') as fd:
fd.write(r.content)
else:
with open(fail_file,'a+') as ff:
ff.write(voiceid + '\n')
except:
prin("fail")
with open(fail_file,'a+') as ff:
ff.write(voiceid + '\n')

r = request.get(url)
r.status_code 获取响应状态码
r.text 获取响应内容
r.headers 获取响应头
r.encoding 获取响应编码
r.content 获取二进制响应内容
r.json() 获取JSON响应内容

python 爬取媒体文件(无防火墙)的更多相关文章

  1. python 爬取媒体文件(使用chrome代理,启动客户端,有防火墙)

    #coding = utf-8 ''' 中文转经纬度 ''' import time,json import urllib.request from selenium import webdriver ...

  2. scrapy --爬取媒体文件示例详解

    scrapy 图片数据的爬取 基于scrapy进行图片数据的爬取: 在爬虫文件中只需要解析提取出图片地址,然后将地址提交给管道 配置文件中写入文件存储位置:IMAGES_STORE = './imgs ...

  3. python爬取当当网的书籍信息并保存到csv文件

    python爬取当当网的书籍信息并保存到csv文件 依赖的库: requests #用来获取页面内容 BeautifulSoup #opython3不能安装BeautifulSoup,但可以安装Bea ...

  4. python爬取网站数据

    开学前接了一个任务,内容是从网上爬取特定属性的数据.正好之前学了python,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...

  5. python爬取网站数据保存使用的方法

    这篇文章主要介绍了使用Python从网上爬取特定属性数据保存的方法,其中解决了编码问题和如何使用正则匹配数据的方法,详情看下文     编码问题因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这 ...

  6. Python爬取中国天气网

    Python爬取中国天气网 基于requests库制作的爬虫. 使用方法:打开终端输入 “python3 weather.py 北京(或你所在的城市)" 程序正常运行需要在同文件夹下加入一个 ...

  7. 用Python爬取B站、腾讯视频、爱奇艺和芒果TV视频弹幕!

    众所周知,弹幕,即在网络上观看视频时弹出的评论性字幕.不知道大家看视频的时候会不会点开弹幕,于我而言,弹幕是视频内容的良好补充,是一个组织良好的评论序列.通过分析弹幕,我们可以快速洞察广大观众对于视频 ...

  8. 毕设之Python爬取天气数据及可视化分析

    写在前面的一些P话:(https://jq.qq.com/?_wv=1027&k=RFkfeU8j) 天气预报我们每天都会关注,我们可以根据未来的天气增减衣物.安排出行,每天的气温.风速风向. ...

  9. Python 爬取途虎养车 全系车型 轮胎 保养 数据

    Python 爬取途虎养车 全系车型 轮胎 保养 数据 2021.7.27 更新 增加标题.发布时间参数 demo文末自行下载,需要完整数据私聊我 2021.2.19 更新 增加大保养数据 2020. ...

随机推荐

  1. kali渗透综合靶机(十一)--BSides-Vancouver靶机

    kali渗透综合靶机(十一)--BSides-Vancouver靶机 靶机下载地址:https://pan.baidu.com/s/1s2ajnWHNVS_NZfnAjGpEvw 一.主机发现 1.n ...

  2. 2019-11-27-WPF-全屏透明窗口

    原文:2019-11-27-WPF-全屏透明窗口 title author date CreateTime categories WPF 全屏透明窗口 lindexi 2019-11-27 09:22 ...

  3. PyTestReport 自动化报告

    安装 pip install PyTestReport pytest框架执行命令 pytest.main(["-s", "test_login.py", &qu ...

  4. @property与@xxx.setter的用法

    类中@property与@xxx.setter的方法介绍. 简单说,@property就是将定义的函数(方法)当作属性对象使用,不需要像调用函数那样去调用,而@xxx.setter是为@xxx的这样函 ...

  5. 回忆C++

    内联函数 内联函数适用于函数较为短小的情况. 内联函数存在的意义是:提高程序运行效率. 内联函数的缺点:如果一个内联函数太长且频繁调用,会导致生成的可执行程序较大. 静态链接库会被嵌入到生成的可执行程 ...

  6. JVM源码分析之MetaspaceSize和MaxMetaspaceSize的区别

    JVM加载类的时候,需要记录类的元数据,这些数据会保存在一个单独的内存区域内,在Java 7里,这个空间被称为永久代(Permgen),在Java 8里,使用元空间(Metaspace)代替了永久代. ...

  7. oracle查询中会使索引无效的情况总结

    总结一下oracle中会使索引无效的情况 1 无where条件: 2 索引列进行运算时: 3 使用like,并且通配符在前的情况: 4 字符型字段为数字时在where条件里不添加引号: 5 not i ...

  8. 数字,字符串,time模块,文本进度条

    数字和字符串 数字类型 整形 整数, 1/2/3/12/2019 整形用来描述什么, 身高/年龄/体重 age = 18 height = 180 浮点型 浮点数,小数 salary = 10 pri ...

  9. LearnOpenGL.PBR.光照

    光源辐射率:      辐射率(radiance)表示光源在给定立体角ω下的辐射通量(或光源发射的能量).     那么假设立体角ω无限小时,辐射率就表示单束光线(或说某个单一方向)的辐射通量. 点光 ...

  10. 团队——Alpha2版本发布

    这个作业属于哪个课程 课程链接 这个作业要求在哪里 作业要求的链接 团队名称 杨荣模杰和他的佶祥虎 这个作业的目标 发布并说明产品Alpha2版本 一.团队成员的学号姓名列表 学号 姓名 201731 ...