Python Selenium if字符串包含精确匹配
我正在尝试使用python selenium检查URL,以查看站点所在的页面。我有以下网址Python Selenium if字符串包含精确匹配,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我正在尝试使用python selenium检查URL,以查看站点所在的页面。我有以下网址 http://www.example.com http://www.example.com/page1 http://www.example.com/contact 我正在使用这个python if "http://www.example.com" in url: print("The URL is homepage") else: print("The URL is not homep
http://www.example.com
http://www.example.com/page1
http://www.example.com/contact
我正在使用这个python
if "http://www.example.com" in url:
print("The URL is homepage")
else:
print("The URL is not homepage")
这不起作用,因为所有URL都包含字符串,如何更改它使其仅适用于精确匹配?使用相等运算符
==
,如下所示:
if url == "http://www.example.com":
print("The URL is homepage")
else:
print("The URL is not homepage")
按照惯例,将变量名放在等式运算符的LHS上,并将测试它的字符串放在RHS上。使用等式运算符
==
,如下所示:
if url == "http://www.example.com":
print("The URL is homepage")
else:
print("The URL is not homepage")
按照惯例,将变量名放在等式运算符的LHS上,并将测试它的字符串放在RHS上。如果您想更进一步,可以使用
重新导入
a=re.compile('.*example\.com$'))
#.*忽略example.com前面的内容
# \. 逃之夭夭
#$表示这必须是字符串的结尾
如果a.match(url):#如果您想更进一步,可以使用
重新导入
a=re.compile('.*example\.com$'))
#.*忽略example.com前面的内容
# \. 逃之夭夭
#$表示这必须是字符串的结尾
如果a.match(url):#