python - 用于匹配特定后缀域的 url 正则表达式
问题描述
它是一个关键字排名模块。我需要搜索包括 co.in,co.uk 在内的后缀域
我尝试了以下代码,但它不起作用
代码的客户端域是:www.domain_name.com
搜索列出了客户端域的所有 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))
输出 无
解决方案
我不太清楚您需要什么输出,但这可能会让您入门:
print(re.findall("\.(\w+)", clientdomain))
它输出除了 URL 的第一个(最有可能是“www”)部分之外的所有部分的列表:
['google', 'com']
推荐阅读
- django - geo django 找不到指定的模块
- javascript - 使用 javascript 将元素定位更改为绝对位置时出错
- python - 如何在 python 中比较两个 excel 工作簿?
- google-apps-script - 如何在 GOOGLE Forms 中自动选择日期
- azure-data-explorer - kusto 查询语言 - 将参数值传递给用户定义的函数
- c++ - DX12 初始化失败 VS2019
- mysql - 如何为具有数据类型 Json 的列的 MySQL 编写选择查询?
- vb.net - “&”符号的转义字符是什么?对于 vb.net
- javascript - VSCode:TS/JS 语言功能禁用语法高亮
- ssh - 有没有办法在 PyCharm 中分离正在运行的远程 ssh 脚本?