本文整理匯總了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]))