美化组内部服务器E

2024-10-01 17:40:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用beauthulsoup循环访问几百个URL。最近,一个HTTP错误一直困扰着我。我试图构建一个While循环来重复页面的加载,直到URL被加载,但是它仍然显示出来。我已经浏览了我正在手动循环的URL,它们似乎没有任何问题-错误也不是在某个URL上生成的,而是在看似随机的迭代中产生的。在

enter image description here

我试图解决这个问题的代码没有成功:

    gameCount = 0
    for (index, URL) in enumerate(tempLinkList):

        tryCount = 0
        while tryCount < 500:
            tryCount += 1
            try:
                with urllib.request.urlopen(URL) as url:
                    page = url.read()
                soup = BeautifulSoup(page, "html.parser")   
            except:
                time.sleep(0.1)
                continue
            else:
                break

非常感谢您的帮助!在


Tags: 代码inhttpurlforindex错误page
1条回答
网友
1楼 · 发布于 2024-10-01 17:40:22

状态码500表示

The server encountered an unexpected condition which prevented it from fulfilling the request.

这意味着,你的代码没有问题。问题出在网站这边。除了在一段时间后重新发送请求外,您对此无能为力。在

一般来说,状态码几百位的数字有特定的含义。在

来自Wikipedia

  • 1xx-信息性响应
  • 2xx-成功
  • 3xx-重定向
  • 4xx-客户端错误
  • 5xx-服务器错误

Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request.

相关问题 更多 >

    热门问题