-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
没有保存成 .txt 文件 #53
Comments
我又试了用 tee 命令把 terminal 中的输出保存成 TXT 文件。但是结果如下: python weiboSpider.py |tee -a weibozanshuo.txt Traceback (most recent call last): 我用的系统是 Ubuntu 18.04 系统语言是英文。 |
看起来是微博发布工具为None,在写文件之前出错,所以weibo没有保存。如果不需要“发布工具”,也可以去掉write_txt中的 + u"发布工具: " + self.publish_tool[i - 1] + "\n\n" ,能否提供微博id测试下,谢谢 |
@dataabc 谢谢你的回复。要爬微博ID是 1711243680。 comment掉你说的语句后,所得的反馈如下: $python weiboSpider.py |tee -a weibozanshuo1.txt Traceback (most recent call last): 我在网上查的是说 str 和 uni 类型不能相加。要用 unicode()函数 我现在尝试用script命令在纪录爬虫结果。 |
似乎是跟我电脑设置有关,这是script出来的.txt文件开头的一部分,可以看到抓取的微博能正常显示出来,但是抓取微博前terminal中的一些语句在.txt文件中呈现乱码 weibospider�[00m$ python app.py�������������sudo gedit /etc/default/grub &��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K��[K�������python wei�bosp�i��[K��[K��[KSpider.py
|
似乎找到出现cannot concatenate 'str' and 'NoneType' objects的原因了。我刚刚试了下,发现第一次出现是在爬了100多页以后。然后,又测试了几次,出现很多None,而且页数小于100,甚至出现了第一条微博为None的情况,怀疑是因为爬取速度过快且数量较多,账号被微博限制了,使很多应该爬取的信息变成了None,导致在组合信息时出现上述错误。 for page in tqdm(range(1, page_num + 1), desc=u"进度"): 可以控制速度,每循环一次代表爬取一页,你可以做一下判断,如 from time import sleep
......
for page in tqdm(range(1, page_num + 1), desc=u"进度"):
if page % 5==0:
sleep(3)
...... 表示每爬5页暂停3秒,具体应该多少页暂停你可以自己测试,也可以参考#8 |
谢谢回复。不过我的号应该没有被微博限制,因为我只要不输出成 txt 格式,只在terminal中爬取,就不会报错。所以我用 script 把terminal中的爬取结果全部纪录并存成 txt 格式,成功爬完了万余条。 这个错误看来是我个人问题,我自己再试下就好,可以关闭 issue 啦。 |
我又试了下爬另几个人的百余条微博,就没有上述问题,成功输出 .txt 文件了。看来是个例,不用担心。 |
终端反馈如下:
进度: 100%|██████████| 1146/1146 [1:03:48<00:00, 1.19it/s]
共11078条微博
('Error: ', TypeError("cannot concatenate 'str' and 'NoneType' objects",))
Traceback (most recent call last):
File "weiboSpider.py", line 343, in write_txt
u"发布工具: " + self.publish_tool[i - 1] + "\n\n"
TypeError: cannot concatenate 'str' and 'NoneType' objects
信息抓取完毕
运行了好久,终于抓了万余条微博。但是抓取的微博并没保存在 /weibo 文件夹里。反而是之前填错 Cookie 时运行后保存了3条空白的 .txt 文件。也没看到别人有这个问题。现在爬的微博在我终端里,但是因为微博太多了,终端只显示了一部分,求教现在怎么办?
The text was updated successfully, but these errors were encountered: