[問題] python 將爬出來的資料匯出至檔案
大家好,小弟本身沒有什麼程式背景
最近開始接觸到了 Python 但是遇到了一些問題想請教一下大家
小弟按照著教學把網路上要得資訊爬下來
print 也有資料出來
但是希望可以把print 出來的資料輸出成 txt or csv
但是一直無法成功,想請教一下前輩是哪邊的邏輯有問題
import requests
from bs4 import BeautifulSoup
res = requests.get("http://www.yodobashi.com/%E3%82%B9%E3%83%81%E3%83%BC%E3%83%A0%E3%82%AA%E3%83%BC%E3%83%96%E3%83%B3%E3%83%AC%E3%83%B3%E3%82%B8/ct/6567_500000000000000211/?count=48&discontinued=false&disptyp=01&oword=Hitachi&page=1&searchtarget=prodname&sorttyp=COINCIDENCE_RANKING&ginput=Hitachi")
soup = BeautifulSoup(res.text)
for item in soup.select('.pListBlock'):
f = open('A.txt', 'w', encoding = 'UTF-8')
f.write (item.select('.pName')[0].text,item.select('.red')[0].text)
f.close ()
requests.get的縮址 http://goo.gl/PS3c4K
感謝大家 @@
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.227.175.246
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1457407103.A.502.html
※ 編輯: brightsu (125.227.175.246), 03/08/2016 11:19:34
→
03/08 15:29, , 1F
03/08 15:29, 1F
抱歉,小第一次發文沒注意到直接貼上所有的排版都跑掉了
※ 編輯: brightsu (125.227.175.246), 03/08/2016 16:44:12
→
03/08 16:53, , 2F
03/08 16:53, 2F
→
03/08 16:54, , 3F
03/08 16:54, 3F
→
03/08 16:55, , 4F
03/08 16:55, 4F
→
03/08 18:40, , 5F
03/08 18:40, 5F
推
03/10 22:34, , 6F
03/10 22:34, 6F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章