#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. MVC 创建Controllers 发生 EntityType has no key defined error

    发生如图错误 只需要在对应的类中指定Key即可 添加引用 : System.ComponentModel.DataAnnotations 参考:https://stackoverflow.com/qu ...

  2. JS运算符类型

    一.运算符类型 1.算术运算符: 用于各类数值运算,包括加(+).减(-).乘(*).除(/).求余(或称模运算,%).自增(++).自减(--)共七种. 2.关系运算符: 用于比较运算.包括大于(& ...

  3. Maven快速入门--Idea版

    目录 1.web项目的基本知识 1.1 项目构建 1.1.1传统的构建过程如下: 1.1.2 mavn构建项目 1.2 maven构建项目的优点: 2. 依赖管理 2.1 传统依赖管理 2.1.1 手 ...

  4. Lucene queryParser和analysis有什么不同?

    在Lucene1.4.3中,queryParser和analysis分成独立的两个包,queryParser作用是解析查询语句,analysis作用是分词,queryParser在解析查询语句的时候会 ...

  5. Linux搭建www,mail,ftp三大DNS服务器

    ##############################-----服务器端----###############################1. 安装bind# yum install bin ...

  6. asp.net core 系列 2 启动类 Startup.CS

    学无止境,精益求精 十年河东,十年河西,莫欺少年穷 学历代表你的过去,能力代表你的现在,学习代表你的将来 在探讨Startup启动类之前,我们先来了解下Asp.NET CORE 配置应用程序的执行顺序 ...

  7. HTML 使用表格制作简单的个人简历

    复习一下HTML,用表格做一个简单的个人简历 <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  8. jQuery基础的HTML与text区别

    浏览器样式 <body> <h1>jQueryAPI特点<a href="#">a标<i>来个斜体</i>签</a ...

  9. ftp上传文件时遇到: ftplib.error_perm: 553 Could not create file

    问题描述 今天在使用python的ftplib模块上传文件时,碰到了这样的问题: ftplib.error_perm: 553 Could not create file. 原因 原因是FTP下对应的 ...

  10. c# 第14节 字符方法、转义字符、字符串的方法

    本节内容: 1:字符的定义 2:字符的方法 3: 转义字符 4:字符串简介 5:字符串方法 1:字符的定义 char与Unicode一一对应,一个char 2个字节. 2:字符的使用方法: 实例: s ...