python scrapy學習-(1)

遇到問題1:write() argument must be str, not bytes
對應的源碼爲

    def parse(self, response):
        filename = "teacher.html"
        open(filename, 'w').write(response.body)

原因:打開文件的格式有問題,追加一個打開文件的格式參數b+ ,以二進制的方式打開就可以了.

    def parse(self, response):
        filename = "teacher.html"
        open(filename, 'wb+').write(response.body)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章