Home  >  Q&A  >  body text

爬虫图片 - 关于Python 爬虫的问题

写了一个从网站批量下载图片的爬虫,其中保存图片的代码:

img_name = pq(picHTML.text).find('.main-image').find('img').attr('alt')//图片的名字
f = open(img_name+'.jpg','ab')

老是报:
invalid mode ('ab') or filename: u'u5939u4e00u4e0bu53efu597d? u65e5u672cu6027u611fu5973u795eu4e2du6751u9759u9999u5927u79c0u7206u4e73 Fu7ea7u8089u5f39u80f8u608du65e0u6bd4.jpg'
的错,求找到原因?

PHP中文网PHP中文网2740 days ago688

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:26:39

    Forgive me for being ignorant. What is the mode of ab? Add content from end of file? I think wb is fine.

    reply
    0
  • Cancelreply