Python大神看下我爬虫下载文档思路可行吗,python大神,如果不想看我的思路和de
Python大神看下我爬虫下载文档思路可行吗,python大神,如果不想看我的思路和de
如果不想看我的思路和debug错误,可以直接看最后一句。
————————————————————————————
如题,我想下载的文档是那种输入网址自动下载的,比如这个:
http://app.sipo-reexam.gov.cn/books/2003/FS3641/DOC/FS3641.doc
现在想用Python的urllib.request.urlretrive函数下载下来这个文档,但是报错。
我的代码和报错信息如下:
这是代码:
import urllib.request, urllib.error, urllib.parseimport osfile_name = 'test.doc'file_path = 'doc'if os.path.exists(file_path) == False: os.makedirs(file_path)local = os.path.join(file_path,file_name)url = 'http://app.sipo-reexam.gov.cn/books/2003/FS3641/DOC/FS3641.doc'urllib.request.urlretrieve(url,local,Schedule)
这是报错信息:
Traceback (most recent call last): File "C:\Users\zhushihao\Desktop\doc.py", line 25, in <module> urllib.request.urlretrieve(url,local,Schedule) File "C:\Python34\lib\urllib\request.py", line 178, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "C:\Python34\lib\urllib\request.py", line 153, in urlopen return opener.open(url, data, timeout) File "C:\Python34\lib\urllib\request.py", line 455, in open response = self._open(req, data) File "C:\Python34\lib\urllib\request.py", line 473, in _open '_open', req) File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain result = func(*args) File "C:\Python34\lib\urllib\request.py", line 1202, in http_open return self.do_open(http.client.HTTPConnection, req) File "C:\Python34\lib\urllib\request.py", line 1177, in do_open r = h.getresponse() File "C:\Python34\lib\http\client.py", line 1172, in getresponse response.begin() File "C:\Python34\lib\http\client.py", line 351, in begin version, status, reason = self._read_status() File "C:\Python34\lib\http\client.py", line 321, in _read_status raise BadStatusLine(line)http.client.BadStatusLine: ''[Finished in 2.3s with exit code 1]
另外 ,我自己考虑到有可能是网站屏蔽非浏览器请求,就想封装一个header,结果提示urlretrieve函数第一个参数只能是string,不能是request对象。
—————————————————————我是最后一句——————————————————————
如何用Python 下载 http://app.sipo-reexam.gov.cn/books/2003/FS3641/DOC/FS3641.doc这样的文档?
编橙之家文章,
相关内容
- 关于Python线程池大小应该控制在什么范围内最适合,
- Python计算10.0/3结果为3.33333333335正常吗,,环境python2.6.
- python语言利用subprocess库调用mplayer时发生错误,pythons
- python如何实现将上传数据中key值做为文件名保存的方法
- Python Pycharm os.system方式调用程序的问题,pycharmos.syste
- Python正则匹配r'\s+'与r'(\s+)'两种方法有何不同,python有
- 删除保留内容外的数据用python方式如何实现,内容pyt
- 谁有数据量大些的敏感词数据表分享一份,十分感谢!,
- Python边下载边播怎么实现?可以不用搭建流媒服务器吗
- :和->在Python程序中的分别代表什么及作用是什么
评论关闭