dataabc / weibo-follow

爬取关注列表中微博账号的微博
179 stars 51 forks source link

你好,出现xpath问题 #7

Closed alfonsocheng1025 closed 4 years ago

alfonsocheng1025 commented 4 years ago

你好,运行的时候出现以下errors: Error: 'NoneType' object has no attribute 'xpath' Traceback (most recent call last): File "D:\github_clone\weibo-follow\weibo_follow.py", line 132, in start self.get_follow_list() # 爬取微博信息 File "D:\github_clone\weibo-follow\weibo_follow.py", line 84, in get_follow_list page_num = self.get_page_num() File "D:\github_clone\weibo-follow\weibo_follow.py", line 58, in get_page_num if selector.xpath("//input[@name='mp']") == []: AttributeError: 'NoneType' object has no attribute 'xpath' 请问如何解决?谢谢!

dataabc commented 4 years ago

说明你速度太快了,降低速度就可以了。具体修改get_follow_list方法:

            if page - page1 == random_pages and page < page_num:
                sleep(random.randint(6, 10))
                page1 = page
                random_pages = random.randint(1, 5)

上面是每爬1到5页,等待6到10秒,你可以加快等待频率或者增加等待时间。

alfonsocheng1025 commented 4 years ago

说明你速度太快了,降低速度就可以了。具体修改get_follow_list方法:

            if page - page1 == random_pages and page < page_num:
                sleep(random.randint(6, 10))
                page1 = page
                random_pages = random.randint(1, 5)

上面是每爬1到5页,等待6到10秒,你可以加快等待频率或者增加等待时间。

感谢回复!这个问题已解决