我正在尝试找出如何检查维基百科文章是否存在。例如,
https://en.wikipedia.org/wiki/Food
但是存在
https://en.wikipedia.org/wiki/Fod
没有,该页面只是说:“维基百科没有具有该确切名称的文章。”
谢谢!
最佳答案
>>> import urllib
>>> print urllib.urlopen("https://en.wikipedia.org/wiki/Food").getcode()
200
>>> print urllib.urlopen("https://en.wikipedia.org/wiki/Fod").getcode()
404
可以吗?
或
>>> a = urllib.urlopen("https://en.wikipedia.org/wiki/Fod").getcode()
>>> if a == 404:
... print "Wikipedia does not have an article with this exact name."
...
Wikipedia does not have an article with this exact name.
关于Python:检查维基百科文章是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31606676/