用于匹配特定后缀域的url的正则表达式

问题描述 投票:-2回答:1

它是关键字排名模块。我需要搜索后缀域名,包括co.in,co.uk 我尝试了以下代码,但它无法正常工作 代码的客户端域名是:www.domain_name.com 搜索列出了clientdomain的所有URL

for j in search(s, tld="com|co.in", num=100, stop=1, pause=2):
        domain=urlsplit(j)[1].split(':')[0]
        if clientdomain == domain:
            b=c
            d=j
            h=str(now)
            o.append(b)
            m.append(d)
            flash(d)
            flash(s)
            flash(b)
            #print("The position of the google search result is:",b)
            #print("The full url:",d)
            #print("The keyword is:",s)
            #print("The date of search:",str(now))
        else:
            hasRank = False
        c=c+1
    c=0
if(hasRank == False):
        print("Uh oh, you're website is not ranked among the top 100 results. Sorry :-(")

我试图使用正则表达式,但不起作用

   import re
   clientdomain = "www.google.com"
   print (re.search("(www.?://[^\s]+)", clientdomain))

输出无

python
1个回答
0
投票

我不太清楚你需要什么输出,但这可能会让你开始:

print(re.findall("\.(\w+)", clientdomain))

它会输出除URL的第一个(最可能是'www')部分之外的所有部分:

['google', 'com']
© www.soinside.com 2019 - 2024. All rights reserved.