我有一個名為的變數all_urls- 它包含一個 URL 串列,例如:
https://website.com/image1
https://website.com/image2
https://website.com/image3
我想使用 for 回圈列印每個 URL。
for url in all_urls:
print(url)
但我最終得到的是:
h
t
t
p
s
(and so on)
有誰知道如何修復它以便程式回傳每個 URL?謝謝。
uj5u.com熱心網友回復:
你可以試試這個:
for url in all_urls.split('\n'):
print(url)
我在想的是你有一個字串而不是一個串列,所以當你回圈遍歷變數的所有元素時,它只會列印單個字符。
這樣,split('\n')將允許通過在新行上拆分來生成串列,其中每個元素將是單個 url。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478743.html
標籤:Python python-3.x 网页抓取
