cola icon indicating copy to clipboard operation
cola copied to clipboard

develop分支中微博parser出错

Open hitalex opened this issue 10 years ago • 7 comments

出错提示:

Error when handle bundle: 1644564144, url: http://weibo.com/aj/mblog/mbloglist?count=15&pre_page=2&uid=1644564144&end_id=3778591994786968&_t=0&_k=1416407703559230&__rnd=1416407854641&pagebar=1&max_id=3768747372034188&page=2 'NoneType' object has no attribute 'text' Traceback (most recent call last): File "/home/kqc/github/cola/cola/job/executor.py", line 504, in _parse_with_process_exception res = self._parse(parser_cls, options, bundle, url) File "/home/kqc/github/cola/cola/job/executor.py", line 430, in _parse **options).parse() File "/home/kqc/github/cola/contrib/kweibo/parsers.py", line 207, in parse forwards = func_div.find('a', attrs={'action-type': action_type_re("forward")}).text AttributeError: 'NoneType' object has no attribute 'text'

另外,@chineking 能否告知你是如何查看 http://weibo.com/aj/mblog/mbloglist?count=15&pre_page=2&uid=1644564144&end_id=3778591994786968&_t=0&_k=1416407703559230&__rnd=1416407854641&pagebar=1&max_id=3768747372034188&page=2 返回的数据的(用的什么工具,以后出错我也可以自行解决)?返回的数据似乎不能直接错位html直接显示。

hitalex avatar Nov 20 '14 02:11 hitalex

我用chrome查看了一下,其中得到的data(html)也不是直接用于展示的。

hitalex avatar Nov 20 '14 02:11 hitalex

cola会重试出错的页面,这个页面在多次重试后还是会出现么?

通常来说,调试的话直接查看页面的dom树,因为这些html会被插入到当前网页里。所以可以用bs4解析dom树以后基本和网页一样,只是说只是网页中的一部分而已。

qinxuye avatar Nov 20 '14 03:11 qinxuye

是多次出现的。

可能是网页结构发生变化,但是之前也用过,却没有出现这个错误。我再试试。

如果这些html会被插入到当前页面,那直接用chrome的开发者工具看就可以了,这个我也再试试看。

hitalex avatar Nov 20 '14 03:11 hitalex

此行出现解析错误:https://github.com/chineking/cola/blob/develop/contrib/weibo/parsers.py#L132

原来的代码:divs = soup.find_all('div', attrs={'class': 'WB_feed_type'}, mid=True)

建议更改为:divs = soup.find_all('div', attrs={'class': 'WB_feed_type SW_fun S_line2 '}, mid=True)

hitalex avatar Nov 20 '14 08:11 hitalex

原则上,上面的代码找出来的div应该是包括下面的div的。这样做的理由是什么呢?

qinxuye avatar Nov 20 '14 08:11 qinxuye

这里比较class的attrs时不是绝对相等么?我不清楚bs4的处理方式。但是之前的那种确实找不到任何div。

hitalex avatar Nov 20 '14 08:11 hitalex

不是,这里find_all方法找出来的是包含这个class的就都会出现。之前这种找不到确实比较费解。这个有待考证

qinxuye avatar Nov 20 '14 08:11 qinxuye