Py学习  »  Python

python中url的正则表达式

ching-yu • 5 年前 • 1701 次点击  

我想删除句子中的所有URL。
这是我的代码:

import ijson
f = open("/content/drive/My Drive/PTT 爬蟲/content/MakeUp/PTT_MakeUp_content_0_1000.json")
objects = ijson.items(f, 'item')

for obj in list(objects):
    article = obj['content']
    ret = re.findall("http[s*]:[a-zA-Z0-9_.+-/#~]+ ", article) # question here
    for r in ret:
      article = article.replace(r, "")
    print(article)

但是“http”的url仍然留在句子中。

article_example = "眼影盤長這樣 http://i.imgur.com/uxvRo3h.jpg 說真的 很不好拍"

知道吗? 谢谢你的帮助。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38386
 
1701 次点击  
文章 [ 3 ]  |  最新文章 5 年前