小编Ant*_*ill的帖子

简单的网络爬虫

我在python写了下面的程序很简单的网络爬虫,但是当我运行它,它返回我"NoneType"对象不是可调用的",你能帮帮我吗?

import BeautifulSoup
import urllib2
def union(p,q):
    for e in q:
        if e not in p:
            p.append(e)

def crawler(SeedUrl):
    tocrawl=[SeedUrl]
    crawled=[]
    while tocrawl:
        page=tocrawl.pop()
        pagesource=urllib2.urlopen(page)
        s=pagesource.read()
        soup=BeautifulSoup.BeautifulSoup(s)
        links=soup('a')        
        if page not in crawled:
            union(tocrawl,links)
            crawled.append(page)

    return crawled
crawler('http://www.princeton.edu/main/')
Run Code Online (Sandbox Code Playgroud)

beautifulsoup python-2.7

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

beautifulsoup ×1

python-2.7 ×1