我想打印所有在特定网页上的网址。下面的代码没有错误,但无法在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
我想你是说。。。在
…这对你的代码有效。在
相关问题 更多 >
编程相关推荐