我想用逗号分隔网址
代码:
for link in v.find_all('a'):
print (link.get('href'))
输出:
xxxx@xxxx-K43U:~/Desktop$ python p.py
https://ecs7.tokopedia.net/img/product-1/2016/1/28/22599505/22599505_ab305ff4-e19f-489e-bcdc-113aeb7581ea.jpg
https://ecs7.tokopedia.net/img/product-1/2016/1/28/22599505/22599505_8d47964f-75af-42bc-9af8-b60e4562ae01.jpg
https://ecs7.tokopedia.net/img/product-1/2016/1/28/22599505/22599505_9cc59e50-ac85-4046-83df-ae3f53042f19.jpg
https://ecs7.tokopedia.net/img/product-1/2016/1/28/22599505/22599505_48cf7f0e-b70c-424d-8000-5ca7f842b1e3.jpg
https://ecs7.tokopedia.net/img/product-1/2016/1/28/22599505/22599505_2cce9f72-85dd-4006-a306-d7bbf83a45e4.jpg
答案 0 :(得分:2)
使用str.join()
:
print(','.join([link.get('href') for link in v.find_all('a')])
请注意,如果您要将网址转储到文件中,最好使用csv
module.