CSV文件:在Python中打开,仅打印链接

时间:2019-06-06 21:05:35

标签: python-3.x csv

我有CSV文件,其中一些链接存储在其中一列中。我只想阅读链接并打印出来。我尝试使用以下代码,但输出为none。

import csv
filename ='abc.csv'
with open(filename,'rb') as f:
    reader = csv.reader(f)
    for row in reader:
     for item in row:
         if item.startswith('http'):
             print(item)

1 个答案:

答案 0 :(得分:0)

=ARRAYFORMULA({SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY("♠"&SORT(UNIQUE(FILTER(A2:A, A2:A<>"")))&
 TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(QUERY(TRANSPOSE(QUERY(QUERY(A2:C,
 "select B,sum(C) where B<>'' group by B pivot A", 0), "offset 1", 0)), "offset 1", 0)), 
 "♠ ♦"&TRANSPOSE(SORT(UNIQUE(FILTER(B2:B, B2:B<>""))))&"♦"&QUERY(TRANSPOSE(QUERY(QUERY(A2:C,
 "select B,sum(C) where B<>'' group by B pivot A", 0), "offset 1", 0)), "offset 1", 0), ))
 , , 999^99))&"♠ ♦Total:♦"&MMULT(QUERY(TRANSPOSE(QUERY(QUERY(A2:C,
 "select B,sum(C) where B<>'' group by B pivot A", 0), "offset 1", 0)), "offset 1", 0)*1,
 TRANSPOSE(SPLIT(REPT(COUNTUNIQUE(B2:B)&"♦", COUNTUNIQUE(B2:B)), "♦")^0)), , 999^99)), 
 "♠")), "♦"); "", "Total:", SUM(C2:C)})

如果要确保该行以“ http”开头,则应输入:

line [0] .startswith(“ http”),因为行列表的第一个元素是字符串。