spider.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:TSpider 作者: Twi1ight 项目源码 文件源码
def normalize_url(url):
        """
        :param url:
        :return:
        """
        # only hostname
        if not '/' in url:
            return 'http://{}'.format(url)
        p = urlparse.urlsplit(url)
        # www.test.com/index.php
        # exclude /xxxxx/index.php
        if not p.netloc:
            if url.startswith('/'):
                # /xxxxx/index.php
                return ''
            else:
                # www.test.com/index.php
                return 'http://{}'.format(url)
        # //www.test.com/index.php
        if not p.scheme:
            url = urlparse.urlunsplit(('http', p.netloc, p.path or '/', p.query, p.fragment))
        return url
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号