python - Regex with negation for extracting web link
问题描述
I have a text fragment:
.....https://www.one.com/privacy/\............http://two.com/terms/'.............https://three.com/pricing/\..........https://four.com/widget/wg74ythx;.........http://five.com/pricing .........
My code for extracting web links:
link = re.compile(r'https?://(\w.*?)(\\|;|\'|\s)')
But I need to exclude from my results all links with the words "privacy" or "widget". I`m stuck here, and I need the help of the community.
解决方案
If you don't need a compile object you could do something like
s = mystring
urls = [url[0] for url in re.findall(r'https?://(\w.*?)(\\|;|\'|\s)',s) \
if not re.search('privacy|widget',url[0])]
推荐阅读
- linux - 在 kubuntu 上,unity3d 无法选择文件菜单
- python - 谷歌云计算上的“ModuleNotFoundError:没有名为‘pycocotools’的模块”
- python - 使用 Beautiful Soup 从抓取的数据中写入 CSV 文件
- php - 将 API 令牌安全保存在数据库中
- c# - Hello World Internet Explorer 扩展(附加)
- javascript - 即使控制台日志显示该值,获取 null 也不是对象错误
- html - 使用 Google 字体的 Roboto 'Thin'
- javascript - 你如何抓取禁用 DevTools 的网站
- c - C - 从数组(结构数组)中删除学生,但平均成绩最高的 10 人除外
- php - Doctrine ManyToOne Relation 未使用 findBy 方法查找数据