MillionHeroes icon indicating copy to clipboard operation
MillionHeroes copied to clipboard

运行两次之后发生了“find_all”返回空值的错误

Open YuMXuan opened this issue 7 years ago • 7 comments

Traceback (most recent call last): File "hero.py", line 56, in <module> results = baiduSearch.search(keyword) File "D:\MillionHeroes-master\baiduSearch\search.py", line 8, in search results = process.page(page) File "D:\MillionHeroes-master\baiduSearch\process.py", line 46, in page result_set = result_set.find_all('div', class_='c-container') # 结果class固定,其余为硬广 AttributeError: 'NoneType' object has no attribute 'find_all'

一开始运行正常,尝试几次之后突然出现错误。

YuMXuan avatar Jan 07 '18 11:01 YuMXuan

我这边没问题 你看是不是汉王识别的次数用完了。你可以用自己的

wuditken avatar Jan 07 '18 12:01 wuditken

汉王次数没有用完,问题识别没有问题,就是答案出不来了 主要是没动代码突然出的问题,头疼

YuMXuan avatar Jan 07 '18 12:01 YuMXuan

你换一个识别图片看看

wuditken avatar Jan 07 '18 13:01 wuditken

我也出现这问题,应该是要识别的图片不对,没有文字就报这个错误 Traceback (most recent call last): File "hero.py", line 56, in results = baiduSearch.search(keyword) File "C:\Users\Administrator\Pictures\baiduSearch\search.py", line 8, in search results = process.page(page) File "C:\Users\Administrator\Pictures\baiduSearch\process.py", line 46, in page result_set = result_set.find_all('div', class_='c-container') # 结果class固定,其余为硬广 AttributeError: 'NoneType' object has no attribute 'find_all'

C:\Users\Administrator\Pictures>python hero.py

wuditken avatar Jan 07 '18 14:01 wuditken

统一更改了一下图片路径,运行了一下 图片的截图看了一下是对的 识别出来的问题的文字是对的 问题可能出在搜索的那个部分 search.py 和 process.py的results可能有点问题,貌似没有返回值

YuMXuan avatar Jan 07 '18 15:01 YuMXuan

还没解决吗?你可以试试运行下面的代码,看看搜索出来没 `import baiduSearch

keyword = '标志是雪山和雄狮的好莱坞电影公司分别是?'

convey = 'n'

if convey == 'y' or convey == 'Y': results = baiduSearch.search(keyword, convey=True) elif convey == 'n' or convey == 'N' or not convey: results = baiduSearch.search(keyword) else: print('输入错误') exit(0) count = 0 for result in results: #print('{0} {1} {2} {3} {4}'.format(result.index, result.title, result.abstract, result.show_url, result.url)) # 此处应有格式化输出 print('{0}'.format(result.abstract)) # 此处应有格式化输出 count=count+1 if(count == 2): break`

wuditken avatar Jan 08 '18 02:01 wuditken

刚刚试了一下,有些题目能搜索出来,有些不行,难道是广告?? 我下一次换bing搜索试试

YuMXuan avatar Jan 08 '18 05:01 YuMXuan