广州linux

当前位置:   网站首页 >> 网络杂谈

vb写爬虫需要用到的一个相对路径转绝对路径function


本来想用python的scrapy写的爬虫,无奈scrapy刚入门,因为要赶这个爬虫,所有用熟悉的vb写了,下面是相对路径转绝对路径function,欢迎python大神发上python上相应的代码学习一下


url="http://www.xxx.com/aaa/bbb"

Function getAbsolutelyUrl(newurl As String)

If Right(url, 1) <> "/" Then url = url & "/"

a = InStr(newurl, "http://") + InStr(newurl, "https://")

If a = 0 Then

    If Mid(newurl, 1, 1) = "/" Then

    start = InStr(8, url, "/")

        If start = 0 Then

        host = url

        Else

        host = Mid(url, 1, start - 1)

        End If

    getAbsolutelyUrl = host & newurl

    Else

        If Mid(newurl, 1, 3) = "../" Then

        countxd1 = UBound(Split(newurl, "../")) '得到多少个../

        countxd = Split(url, "/")

        countxd2 = UBound(countxd)

        countxd3 = countxd2 - countxd1

        For i = countxd3 To countxd2 - 1

        houmian = houmian & countxd(i) & "/"

        Next i

        newhost = Left(url, InStr(url, houmian) - 1)

        getAbsolutelyUrl = newhost & Right(newurl, Len(newurl) - countxd1 * 3)

        Exit Function

        End If

    getAbsolutelyUrl = url & newurl

    End If

Exit Function

End If

getAbsolutelyUrl = newurl

End Function


发表我的评论

Hi,您需要填写昵称和邮箱!

  • 必填项