本文整理汇总了Python中spider.Spider.linkCallback方法的典型用法代码示例。如果您正苦于以下问题:Python Spider.linkCallback方法的具体用法?Python Spider.linkCallback怎么用?Python Spider.linkCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spider.Spider
的用法示例。
在下文中一共展示了Spider.linkCallback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: response
# 需要导入模块: from spider import Spider [as 别名]
# 或者: from spider.Spider import linkCallback [as 别名]
def response (url, response):
"""A response has been recieved from the spider when contacting a url"""
log.info("Processing %s" % url)
def htmlCallback(url, html):
"""Html has been found in the response"""
log.info(html)
def linkCallback(parentUrl, linkUrl, element):
"""A link has been found in the page being spidered"""
log.info("Link Found: %s %s %s" % (parentUrl, linkUrl, str(element)))
def levelCallback(levelNumber):
"""A new level of the page is being started"""
log.info("Spidering level %d" % levelNumber)
if __name__ == '__main__':
logging.basicConfig(level = logging.INFO,
format = "%(asctime)s %(levelname)s %(threadName)s: %(message)s")
spider = Spider(args.url, threads=args.threads, maxDepth=args.depth)
spider.responseCallback = response
spider.htmlCallback = htmlCallback
spider.linkCallback = linkCallback
spider.levelCallback = levelCallback
spider.spider()