[問題] 關於用beautifulsoup抓資料一問
1.我想抓yahoo知識加的問題裡的發問日期和解決日期
以下是我的程式碼:
import re
import BeautifulSoup
url='http://tw.knowledge.yahoo.com/question/question?qid=1609042207523 '
data = urllib.urlopen(url).read()
soup = BeautifulSoup.BeautifulStoneSoup(data)
Question_time = soup.table('td')
Question_start_time = Question_time[1]
Question_end_time = Question_time[2]
print Question_start_time
for i in re.compile('>(.+?)<').findall(Question_start_time):
print i
正常應該要印出 2009-06-14 19:25:38
不過卻顯示錯誤:TypeError: expected string or buffer
請問該如何解決這個錯誤呢??
2.我在1.的程式碼底下試著寫下
B_answer = soup.findAll('div',{'class':'main breakfix'})
Best_Answer = B_answer[1]
print Best_Answer[1:20]
如果是pirnt Best_Answer的話可以印出來,但如果後面加個[1:20]的話就會有錯誤
但我的語法應該是沒什麼錯才對,好像Best_Answer已經變成另一種型態的變數了
有人可以解釋一下為什麼會這樣嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.245.199
※ 編輯: hazton 來自: 140.116.245.199 (07/04 23:15)
→
07/05 02:38, , 1F
07/05 02:38, 1F
→
07/05 16:30, , 2F
07/05 16:30, 2F
※ 編輯: hazton 來自: 140.116.245.199 (07/05 16:31)
※ 編輯: hazton 來自: 140.116.245.199 (07/05 21:49)
→
07/05 21:49, , 3F
07/05 21:49, 3F
→
07/05 22:00, , 4F
07/05 22:00, 4F
→
07/05 22:02, , 5F
07/05 22:02, 5F
→
07/05 22:05, , 6F
07/05 22:05, 6F
→
07/06 02:07, , 7F
07/06 02:07, 7F
※ 編輯: hazton 來自: 140.116.245.199 (07/06 02:08)
Python 近期熱門文章
PTT數位生活區 即時熱門文章