美文网首页
Python-解析Robots文件

Python-解析Robots文件

作者: miraclehen | 来源:发表于2018-11-29 12:03 被阅读14次

    以解析百度的Robots文件为例。

    import urllib.robotparser
    
    rp = urllib.robotparser.RobotFileParser()
    rp.set_url('http://www.baidu.com/robots.txt')
    rp.read()
    
    print(rp.can_fetch('Googlebot', 'https://www.baidu.com/baidu'))
    print(rp.can_fetch('Baiduspider', 'https://www.baidu.com/cpro'))
    
    

    相关文章

      网友评论

          本文标题:Python-解析Robots文件

          本文链接:https://www.haomeiwen.com/subject/hcgxcqtx.html