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

2024-04-19 23:14:58 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个关键字排名模块。我需要搜索的后缀域包括公司,英国公司
我尝试了以下代码,但它不起作用
代码的客户端域是:www.domain\u 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))

输出 没有


Tags: the代码inrecomurlsearchif
1条回答
网友
1楼 · 发布于 2024-04-19 23:14:58

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

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

它输出url的除第一个(很可能是“www”)部分以外的所有部分的列表:

['google', 'com']

相关问题 更多 >