gpt4 book ai didi

python - 使用 python 正则表达式从 URL 中分离 Facebook URL 用户 ID

转载 作者:太空宇宙 更新时间:2023-11-04 07:45:42 25 4
gpt4 key购买 nike

好吧,我从 Stack overflow 中找到了这个正则表达式,它可以隔离 URL 和 ID,但是当我尝试在 App Engine (py) 中使用它时,一个错误弹出窗口说“没有什么可重复的,我知道 Python 中有一个错误关于这个正则表达式重复,谁能解决这个问题?tx

  File "C:\Program Files\Python27\lib\re.py", line 244, in _compile
raise error, v # invalid expression
error: nothing to repeat

示例代码

#   patt = '(?:http:\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-]*)?'
# tst = self.request.get("form_fbURL")
# m=re.match(patt,tst)

反正我不是一个好的 python 程序员 :)

最佳答案

有一个urlparse模块来解析url。
urlparse 模块在 Python 3.0 中重命名为 urllib.parse

$ python
>>> from urlparse import urlparse
>>> urlparse('http://www.facebook.com/hello/world.php?id=789')
ParseResult(scheme='http', netloc='www.facebook.com', path='/hello/world.php', params='', query='id=789', fragment='')

关于python - 使用 python 正则表达式从 URL 中分离 Facebook URL 用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8527448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com