尝试打开 URL 时,我在使用 Mechanize 时遇到 406 错误:
for url in urls:
if "http://" not in url:
url = "http://" + url
print url
try:
page = mech.open("%s" % url)
except urllib2.HTTPError, e:
print "there was an error opening the URL, logging it"
print e.code
logfile = open ("log/urlopenlog.txt", "a")
logfile.write(url + "," + "couldn't open this page" + "\n")
continue
else:
print "opening this URL..."
page = mech.open(url)
知道什么会导致 406 错误发生吗?如果我转到有问题的 URL,我可以在浏览器中打开它。