python新手 一段网络爬虫的简单小程序 有些语法以及功能不太懂 求指点
答案:2 悬赏:0
解决时间 2021-02-08 13:41
- 提问者网友:血樱陌殇
- 2021-02-08 05:16
python新手 一段网络爬虫的简单小程序 有些语法以及功能不太懂 求指点
最佳答案
- 二级知识专家网友:花一样艳美的陌生人
- 2021-02-08 06:50
#将b里面的元素全部追加到a里面,保证不重复
def union(a, b):
#b里面的所有元素
for e in b:
#如果不在a里面
if e not in a:
a.append(e)
def crawl_web(seed): # returns index, graph of inlinks
#列表
tocrawl = [seed]
#列表
crawled = []
#字典
graph = {} # <url>, [list of pages it links to]
#字典
index = {}
#不为空
while tocrawl:
#赋值给page,并删除最后一个
page = tocrawl.pop()
#保证不重复的添加
if page not in crawled:
#下面是各种函数的调用
content = get_page(page)
add_page_to_index(index, page, content)
outlinks = get_all_links(content)
graph[page] = outlinks
union(tocrawl, outlinks)
crawled.append(page)
return index, graph
def union(a, b):
#b里面的所有元素
for e in b:
#如果不在a里面
if e not in a:
a.append(e)
def crawl_web(seed): # returns index, graph of inlinks
#列表
tocrawl = [seed]
#列表
crawled = []
#字典
graph = {} # <url>, [list of pages it links to]
#字典
index = {}
#不为空
while tocrawl:
#赋值给page,并删除最后一个
page = tocrawl.pop()
#保证不重复的添加
if page not in crawled:
#下面是各种函数的调用
content = get_page(page)
add_page_to_index(index, page, content)
outlinks = get_all_links(content)
graph[page] = outlinks
union(tocrawl, outlinks)
crawled.append(page)
return index, graph
全部回答
- 1楼网友:糜废丧逼
- 2021-02-08 07:18
没看懂什么意思?
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯