如何使用python正则表达式仅提取联系人页面链接

时间:2019-05-05 19:04:33

标签: python scrapy

我正在测试python列表

urls=[

 'https://www.example.com/about-us/',
 'https://www.example.com/our-projects/',
 'https://www.example.com/3c-metal-group/',
 'https://www.example.com/installation/',
 'https://www.example.com/inspection/',
 'https://www.example.com/contact-us/',
]

我需要匹配About about链接,并且仅从该链接与python regex的链接中联系我们

1 个答案:

答案 0 :(得分:0)

为什么需要正则表达式?您可以只检查字符串中的子字符串:

>>> urls = [ '3cmetal.com/about-us', '3cmetal.com/our-projects', '3cmetal.com/3c-metal-group', '3cmetal.com/installation', '3cmetal.com/inspection', '3cmetal.com/contact-us', ]
>>> [i for i in urls if 'contact' in i]
['3cmetal.com/contact-us']
>>> [i for i in urls if 'contact' in i or 'about' in i]
['3cmetal.com/about-us', '3cmetal.com/contact-us']