在本地主机中运行代码时,出现{"message": "Internal Server Error"}
错误。我认为这是因为使用了浏览器功能。我该如何解决该问题?我认为它发生在这一行:
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
或者还有其他方法可以从Google搜索结果中获取所有超链接
from googlesearch import search
from mechanize import Browser
from fuzzywuzzy import fuzz
def thirdstep(question):
br =Browser()
br.set_handle_robots(False)
br.set_handle_equiv(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
e=0
for url in search(question, tld='es', lang='es', stop=10):
br.open(url)
similarity_value=fuzz.token_set_ratio(question,br.title())
if(similarity_value>e):
e=similarity_value
f=br.title()
g=url
return(g)
EG。第二次世界大战如何结束? => www.primaryhomeworkhelp.co.uk›战争›结束