我无法看到pycharm控制台上的输出,代码随您而来

2024-10-05 11:23:05 发布

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

我想打印所有在特定网页上的网址。下面的代码没有错误,但无法在pycharm控制台上看到所需的结果。任何帮助都将不胜感激。控制台上只出现“你好”。事先非常感谢。在

from sgmllib import SGMLParser
import urllib


class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.urls = []

    def start_a(self, attrs):
        href = [v for k, v in attrs if k == 'href']
        print href
        if href:
        self.urls.extend(href)


usock = urllib.urlopen("http://diveintopython.org/")
parser = URLLister()
parser.feed(usock.read())
print "hello"
usock.close()
parser.close()
for url in parser.urls:
   print url

Tags: inimportselfparserfordefurlliburls
1条回答
网友
1楼 · 发布于 2024-10-05 11:23:05
usock = urllib.urlopen("http://diveintopython.org/")

我想你是说。。。在

usock = urllib.urlopen("http://diveintopython.NET/")

…这对你的代码有效。在

相关问题 更多 >

    热门问题