zhihu-python icon indicating copy to clipboard operation
zhihu-python copied to clipboard

数组越界了

Open ustczen opened this issue 11 years ago • 4 comments

from zhihu import Question

url = "http://www.zhihu.com/question/35564122" question = Question(url) answers = question.get_all_answers() for answer in answers: answer.to_txt() answer.to_md() 跑到一半提示越界了。

ustczen avatar Sep 30 '15 08:09 ustczen

我遇到相同的问题

Traceback (most recent call last): File "test.py", line 235, in main() File "test.py", line 224, in main question_test(url) File "test.py", line 46, in question_test top_answer = question.get_top_answer() File "/Users/mingrui/Documents/PythonZhihu/zhihu-python/zhihu.py", line 313, in get_top_answer for answer in self.get_top_i_answers(1): File "/Users/mingrui/Documents/PythonZhihu/zhihu-python/zhihu.py", line 306, in get_top_i_answers for answer in answers: File "/Users/mingrui/Documents/PythonZhihu/zhihu-python/zhihu.py", line 196, in get_all_answers if soup.find_all("h3", class_="zm-item-answer-author-wrap")[j].string == u"匿名用户": IndexError: list index out of range

看了一下知乎一个问题网页的source之后把出错的那一行改成:

soup.find_all("div", class_="zm-item-answer-author-info")[j].string == u"匿名用户":

就可以了。。。 不太清楚为什么没有和知乎的对应上,我早上用得时候还是可以的,下午就html标记就变了。。。

notanecho666 avatar Nov 05 '15 07:11 notanecho666

是的,知乎有些地方改了,各位发现了自行修改相应源代码就可以了

egrcc avatar Nov 05 '15 15:11 egrcc

thanks

notanecho666 avatar Nov 05 '15 15:11 notanecho666

zhihu.py中第196行和262行 if soup.find_all("h3", class_="zm-item-answer-author-wrap")[j].string == u"匿名用户": 应改为 if soup.find_all("h3", class_="zm-item-answer-author-wrap")[j].text.strip() == u"匿名用户":

asin929 avatar Nov 25 '15 14:11 asin929