[問題] ptt 爬出作者跟文章怎麼存進excel裡?

看板Python作者 (D-O-DoubleG)時間6年前 (2019/03/05 17:21), 編輯推噓2(203)
留言5則, 4人參與, 6年前最新討論串1/1
練習爬蟲的路上先從ptt 下手 最近遇到的困境是該怎麼把爬到的內容存進excel裡 原本是想說利用list 一個存標題、一個存內文,再用dataframe輸出至excel 但一直存不進去,看著錯誤代碼才想到 爬到的不是string 而是 item 或是 object的東西 以下是簡略的程式碼,標題存進title的list、內文存進article裡 ptt_title = soup.select('span.article-meta-value') // 標題 title[count] = ptt_title[2].text content = soup.find(id="main-content").text // 內文 article[count] = content count++ 但顯然.text 是沒辦法直接存入的! 所以想請教版上的各位 還有甚麼辦法可以存進excel呢?? 感謝各位!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.14.44.35 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1551777663.A.3A4.html

03/05 22:21, 6年前 , 1F
pandas
03/05 22:21, 1F

03/05 22:22, 6年前 , 2F
03/05 22:22, 2F

03/05 23:00, 6年前 , 3F
謝謝!關鍵好像是.text()?
03/05 23:00, 3F

03/06 00:47, 6年前 , 4F
df.to_excel
03/06 00:47, 4F

03/06 11:47, 6年前 , 5F
估計是沒轉成text吧
03/06 11:47, 5F
文章代碼(AID): #1SVZz_Ea (Python)
文章代碼(AID): #1SVZz_Ea (Python)