weibo-crawler
weibo-crawler copied to clipboard
请问下面这两个错误我应该怎么修改啊?我的cookie是被封了吗?
请问这两个问题我应该怎么修改代码啊?我的cookie是被封了吗?
Error: 'Weibo' object has no attribute 'cookie' name 'traceback' is not defined Traceback (most recent call last): File "G:\图片\weibo-crawler-master\weibo.py", line 324, in get_long_weibo html = requests.get(weibo_link, cookies=self.cookie).content AttributeError: 'Weibo' object has no attribute 'cookie'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "G:\图片\weibo-crawler-master\weibo.py", line 743, in get_one_weibo weibo = self.get_long_weibo(weibo_id) File "G:\图片\weibo-crawler-master\weibo.py", line 335, in get_long_weibo traceback.print_exc() NameError: name 'traceback' is not defined
因为之前爬取长微博时发生错误,所以改了get_long_weibo的这段代码 def get_long_weibo(self, weibo_link): try: while True: html = requests.get(weibo_link, cookies=self.cookie).content selector = etree.HTML(html) if selector is not None: info = selector.xpath("//div[@class='c']")[1] wb_content = info.xpath("div/span[@class='ctt']") if len(wb_content) >= 1: wb_content = wb_content[0].xpath("string(.)").replace(u"\u200b", "").encode(sys.stdout.encoding, "ignore").decode( sys.stdout.encoding) return wb_content except Exception as e: print("Error: ", e) traceback.print_exc()
加上import traceback应该就可以了。