我根本不擅长正则表达式.
我已经使用了大量的框架代码到今天为止,但我无法找到一个可以媲美像一个URL http://www.example.com/etcetc也能赶上像www.example.com/etcetc和example.com/etcetc.
任何帮助都会很棒.多谢你们!
例如:
string = "This is a link http://www.google.com"
Run Code Online (Sandbox Code Playgroud)
我怎样才能提取"http://www.google.com"?
(每个链接的格式相同,即'http://')
我有一个巨大的网址列表,都是这样的:
http://www.example.com/site/section1/VAR1/VAR2
Run Code Online (Sandbox Code Playgroud)
其中VAR1和VAR2是网址的动态元素.我想要做的是从这个url字符串中只提取VAR1.我试过使用urlparse,但输出看起来像这样:
ParseResult(scheme='http', netloc='www.example.com', path='/site/section1/VAR1/VAR2', params='', query='', fragment='')
Run Code Online (Sandbox Code Playgroud) 我想删除句子中的所有网址。
\n这是我的代码:
\nimport ijson\nf = open("/content/drive/My Drive/PTT \xe7\x88\xac\xe8\x9f\xb2/content/MakeUp/PTT_MakeUp_content_0_1000.json")\nobjects = ijson.items(f, \'item\')\n\nfor obj in list(objects):\n article = obj[\'content\']\n ret = re.findall("http[s*]:[a-zA-Z0-9_.+-/#~]+ ", article) # Question here\n for r in ret:\n article = article.replace(r, "")\n print(article)\nRun Code Online (Sandbox Code Playgroud)\n但句子中仍然留下了一个带有“http”的URL。
\narticle_example = "\xe7\x9c\xbc\xe5\xbd\xb1\xe7\x9b\xa4\xe9\x95\xb7\xe9\x80\x99\xe6\xa8\xa3 http://i.imgur.com/uxvRo3h.jpg \xe8\xaa\xaa\xe7\x9c\x9f\xe7\x9a\x84 \xe5\xbe\x88\xe4\xb8\x8d\xe5\xa5\xbd\xe6\x8b\x8d"\nRun Code Online (Sandbox Code Playgroud)\n我该如何修复它?
\n我有这样的正则表达式:
re.compile(r"((https?):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)", re.MULTILINE|re.UNICODE)
Run Code Online (Sandbox Code Playgroud)
但这不包括hashbangs (#!).我需要改变什么才能让它发挥作用?我知道我可以添加!用#@%etc组合,但是会选择类似的东西
Check this out: http://example.com/something/!!!
Run Code Online (Sandbox Code Playgroud)
而我想避免这种情况.
我想获取要从URL显示的查询名称和值.例如.url='http://host:port_num/file/path/file1.html?query1=value1&query2=value2'
从中解析查询名称及其值并打印它.