免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4097 | 回复: 1
打印 上一主题 下一主题

下载文章的问题?求解答 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-09-02 10:40 |只看该作者 |倒序浏览
# -*- coding: cp936 -*-
import urllib


page = 1
link = 1
url = ['']*350
while page <= 7:
    con = urllib.urlopen('http://blog.sina.com.cn/s/articlelist_1191258123_0_'+str(page)+'.html').read()
    title = con.find(r'<a title')
    href = con.find(r'href=',title)
    html = con.find(r'.html',href)

    i = 0
    while title != -1 and href != -1 and html != -1 and i<50:
        url[i] = con[href + 6:html + 5]
        print link,'---',url[i]
        title = con.find(r'<a title',html)
        href = con.find(r'href=',title)
        html = con.find(r'.html',href)
        i = i + 1
        link = link + 1
    else:
        print '第',page,'页' ,'read finished ......'
    page = page + 1   
else:
    print 'all page find '

j = 0
while j < 350:
    content = urllib.urlopen(url[j]).read()
    print 'downloading......',url[j],j
    open(r'韩寒/'+url[j][-26:],'w+').write(content)
    j = j + 1
else :
    print 'download finished'
   
这是下载韩寒博客全部文章的代码,但只能下载到第一页的50篇,后面的都下载不到了, 不知道为什么?


错误代码:Traceback (most recent call last):
  File "C:\Python27\blog2.py", line 31, in <module>
    content = urllib.urlopen(url[j]).read()
  File "C:\Python27\lib\urllib.py", line 87, in urlopen
    return opener.open(url)
  File "C:\Python27\lib\urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "C:\Python27\lib\urllib.py", line 463, in open_file
    return self.open_local_file(url)
  File "C:\Python27\lib\urllib.py", line 477, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] : ''

求好心人解答,谢谢

论坛徽章:
0
2 [报告]
发表于 2013-09-03 00:13 |只看该作者
本帖最后由 crifan 于 2013-09-03 00:13 编辑

关于下载和导出新浪博客的帖子,我的BlogsToWordpress,都帮你实现好了对应的功能了。
需要看代码的话,可以去参考:
BlogSina.py
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP