本文整理汇总了Python中spider.Spider.walk方法的典型用法代码示例。如果您正苦于以下问题:Python Spider.walk方法的具体用法?Python Spider.walk怎么用?Python Spider.walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spider.Spider
的用法示例。
在下文中一共展示了Spider.walk方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: walk
# 需要导入模块: from spider import Spider [as 别名]
# 或者: from spider.Spider import walk [as 别名]
def walk(self, url, outfile):
self.pageinfo = {}
self.errors = []
Spider.walk(self, url, self.iswebpage)
print("\r[ ] Processed %i urls" % (len(self.pageinfo)))
urlset = ET.Element('urlset', {'xmlns':"http://www.sitemaps.org/schemas/sitemap/0.9"})
for page in self.pageinfo:
url = ET.SubElement(urlset, 'url')
loc = ET.SubElement(url, 'loc')
lastmod = ET.SubElement(url, 'lastmod')
changefreq = ET.SubElement(url, 'changefreq')
priority = ET.SubElement(url, 'priority')
loc.text = page
lastmod.text = self.pageinfo[page]['lastmod']
changefreq.text = self.pageinfo[page]['change']
priority.text = '%0.1f' % self.pageinfo[page]['pri']
tree = ET.ElementTree(urlset)
tree.write(outfile, encoding='utf-8', xml_declaration=True)
if len(self.errors) > 0:
print("[!] The following pages produced errors:")
for e in self.errors:
print(" %i %s" % (e[1], e[0]))