cyang812 / CSDN2HEXO

csdn 博客导出工具
4 stars 2 forks source link

TypeError: 'float' object cannot be interpreted as an integer #1

Closed itning closed 6 years ago

itning commented 6 years ago

python version:3.6.4

article_cnt =  120
Traceback (most recent call last):
  File ".\csdn-spider.py", line 162, in <module>
    save_article_lists(id_title)
  File ".\csdn-spider.py", line 81, in save_article_lists
    for x in range(1,loop_cnt+1):
TypeError: 'float' object cannot be interpreted as an integer
cyang812 commented 6 years ago

确实有这个问题。已经修复了,再试下哦。

itning commented 6 years ago

导出了三篇博文 后报错:

article_cnt =  120
C:\Users\itning\Desktop\CSDN2HEXO-master\CSDN2HEXO-master\blog
http://api.csdn.net/blog/getarticle?access_token=b9d5a033acd54d2187b4253b0f41bf52&id=79961687
http://api.csdn.net/blog/getarticle?access_token=b9d5a033acd54d2187b4253b0f41bf52&id=79951807
http://api.csdn.net/blog/getarticle?access_token=b9d5a033acd54d2187b4253b0f41bf52&id=79933949
Traceback (most recent call last):
  File ".\csdn-spider.py", line 165, in <module>
    save_blog_to_file(id_title)
  File ".\csdn-spider.py", line 140, in save_blog_to_file
    save_article_pic(dir_name)
  File ".\csdn-spider.py", line 119, in save_article_pic
    download_pic(pic)
  File "C:\Users\itning\Desktop\CSDN2HEXO-master\CSDN2HEXO-master\md_parse.py", line 88, in download_pic
    name = url.split('http://img.blog.csdn.net/')[1]+pic_type
IndexError: list index out of range

我在download_pic 这个方法加入print(url+"---"+pic_type)

def download_pic(url):
    r = urllib.request.urlopen(url)               # directly access

    content = r.read()
    if content[0] == 0xff and content[1] == 0xd8 :
        pic_type = '.jpg'
    else:
        pic_type = '.png'

    print(url+"---"+pic_type)

    name = url.split('http://img.blog.csdn.net/')[1]+pic_type
    print('downloading ->',name)

    file_path = os.path.join(name)
    # if not os.path.isfile(file_path):

    with open(name, "wb") as code:
       code.write(content)

打印为:

https://github.com/Netflix/eureka/raw/master/images/eureka_architecture.png---.png

@cyang812

itning commented 6 years ago

I fix this issue in #2