我有一个巨大的 URL 列表,它们都是这样的:
http://www.example.com/site/section1/VAR1/VAR2
其中 VAR1 和 VAR2 是 URL 的动态元素。我只想从此 URL 字符串中提取 VAR1。我尝试使用 urlparse ,但输出如下所示:
ParseResult(scheme='http', netloc='www.example.com', path='/site/section1/VAR1/VAR2', params='', query='', fragment='')
原文由 Hyperion 发布,翻译遵循 CC BY-SA 4.0 许可协议
或者,您可以应用
split()
方法: