Closed bluerthanever closed 3 years ago
还有一个前提,就是,我设置的since_date是1900-01-01,所以不应该这样。 但是我也注意到,好像跳出循环也是通过return来判断的。。。
def get_one_page(self, weibo_id_list):
"""获取第page页的全部微博"""
try:
info = self.selector.xpath("//div[@class='c']")
is_exist = info[0].xpath("div/span[@class='ctt']")
weibos = []
if is_exist:
since_date = datetime_util.str_to_time(self.since_date)
for i in range(0, len(info) - 2):
weibo = self.get_one_weibo(info[i])
if weibo:
if weibo.id in weibo_id_list:
continue
publish_time = datetime_util.str_to_time(
weibo.publish_time)
if publish_time < since_date:
if self.is_pinned_weibo(info[i]):
continue
else:
return weibos, weibo_id_list, False
logger.info(weibo)
logger.info('-' * 100)
weibos.append(weibo)
weibo_id_list.append(weibo.id)
return weibos, weibo_id_list, True
except Exception as e:
logger.exception(e)
我直接改成这样了,然后上面调用这个函数的时候,拆出三个变量,在上面158行的地方if判断这第三个变量大概就可以了吧。。。没仔细测试
Edit: 顺带一提上面的PageParser的get_one_page函数我只是改了return值,加了第三个返回的值,其他的没动。 不知道你们会觉得是放在外面判断好还是怎样。 另外就是207的bug,估计pageparser还要改吧。。。
感谢反馈。
这里确实有问题,建议很好。因为是你发现并提出了解决方案,能否通过pull request提交修改,这样你也可以成为本项目的Contributor。这不是强制的,只是因为这是你的劳动成果,所以提出这个请求,如果明天之前没有提交pull request,我会自己修改。
再次感谢,如果还有建议欢迎继续讨论:smile:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
感谢您申报bug,为了表示感谢,如果bug确实存在,您将出现在本项目的贡献者列表里;如果您不但发现了bug,还提供了很好的解决方案,我们会邀请您以pull request的方式成为本项目的代码贡献者(Contributor);如果您多次提供很好的pull request,我们将邀请您成为本项目的协助者(Collaborator)。当然,是否提供解决方按都是自愿的。不管是否是真正的bug、是否提供解决方案,我们都感谢您对本项目的帮助。
问:请您指明哪个版本出了bug(github版/PyPi版/全部)?
答:应该是github版吧,github下载脚本运行的
问:您使用的是否是最新的程序(是/否)?
答:是,今天刚下的
问:爬取任意用户都会复现此bug吗(是/否)?
答:否
问:若只有爬特定微博时才出bug,能否提供出错微博的weibo_id或url(非必填)?
答: 略
问:若您已提供出错微博的weibo_id或url,可忽略此内容,否则能否提供出错账号的user_id及您配置的since_date,方便我们定位出错微博(非必填)?
答: 略
问:如果方便,请您描述bug详情,如果代码报错,最好附上错误提示。
答:
https://github.com/dataabc/weiboSpider/blob/16fd1d9dabb9839d3562ad61ed93c7eb577a41e7/weibo_spider/spider.py#L158-L161 这个部分,比如我的filter设置的1,也就是只获取原创微博的时候,如果某一页全部都是转发的微博,直接就return了,后面的页数都获取不到了