【发布时间】:2018-08-04 20:10:34
【问题描述】:
我有一个包含 10,000 行的 csv 文件。每行有 8 列。其中一列包含与此类似的文本:
this is a row: http://somedomain.com | some_text | http://someanotherdomain.com | some_more_text
this is a row: http://yetanotherdomain.net
this is a row: https://hereisadomain.org | some_text
我目前正在以这种方式访问此列中的数据:
for row in csv_reader:
the_url = row[3]
# this regex is used to find the hrefs
href_regex = re.findall('(?:http|ftp)s?://.*', the_url)
for link in href_regex:
print (link)
打印语句的输出:
http://somedomain.com | some_text | http://someanotherdomain.com | some_more_text
http://yetanotherdomain.net
https://hereisadomain.org | some_text
如何仅获取 URL?
http://somedomain.com
http://someanotherdomain.com
http://yetanotherdomain.net
https://hereisadomain.org
【问题讨论】:
标签: regex python-3.x csv