[問題] 有辦法寫出自動搜尋比對網頁關鍵字嗎?

看板Python作者 (青龍)時間11年前 (2014/11/16 16:32), 11年前編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
例如我每天有想載的東西 我可以事先設定好所有需要的關鍵字 比如a b c 然後讓程式去搜尋比對網頁內容 有符合的話就自動去點擊相關的連結 接著去點選下載軟體同意 請問有可能辦到嗎? 會很難嗎? 感謝回答~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.29.11 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1416126734.A.08F.html

11/16 16:46, , 1F
找爬蟲相關資料
11/16 16:46, 1F
感謝 我看了一下 import urllib2 from sgmllib import SGMLParser class ListName(SGMLParser): def __init__(self): SGMLParser.__init__(self) self.is_h4 = "" 使用一個變量 is_h4 做標記判定 html 文件中的 h4 標籤,如果遇到 h4 標籤,則將標 籤內的內容加入到 List 變量 name 中。 請問這句話是甚麼意思? 聽起來像是有個list?加入到list裡面是指搜尋網頁關鍵字 然後放進自己list分類嗎? self.name = [] def start_h4(self, attrs): self.is_h4 = 1 def end_h4(self): self.is_h4 = "" def handle_data(self, text): if self.is_h4 == 1: self.name.append(text) 到這裡為止都是在抓網頁關鍵字然後進行歸類嗎? content = urllib2.urlopen('http://list.taobao.com/browse/cat-0.htm').read() listname = ListName() listname.feed(content) for item in listname.name: print item.decode('gbk').encode('utf8') ※ 編輯: seiryou (114.32.29.11), 11/16/2014 17:13:01

11/17 13:20, , 2F
可以看看 http://scrapy.org/
11/17 13:20, 2F
文章代碼(AID): #1KQ64E2F (Python)
文章代碼(AID): #1KQ64E2F (Python)