Re: [問題] 請教ghost.py抓取javascript後

看板Python作者 ( )時間12年前 (2012/06/20 20:02), 編輯推噓2(202)
留言4則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《areyo (沒有名字的怪物)》之銘言: : hi : 謝謝版上許多高手幫忙 : 但有些問題還是想請教一下 : 我的code如下 : from ghost import Ghost : referer_url = "http://www.w3schools.com/js/tryit.asp?filename=tryjs_comments5" : gh = Ghost(wait_timeout=100000) : page,resources = gh.open(referer_url) : result,resources=gh.evaluate("document.getElementById(\"myP\")") : print result : 上面那個URL是個教javascript的網頁,我拿來測試ghost.py : 抓完後,result的確是有東西,但是我怎麼印出它的值呢? : 謝謝 http://www.w3schools.com/js/tryit.asp?filename=tryjs_comments5 的實際網頁在iframe裡 網址用 http://www.w3schools.com/js/tryit_view.asp?filename=tryjs_comments5 才有東西 然後 >>> gh.evaluate("document.getElementById('myP').innerHTML") (u'x=7', []) 覺得 DOM 太難用的話有 https://bitbucket.org/olauzanne/pyquery/ 大概就 gh.content 吐 html 出來分析 (沒用過) -- http://head.barepants.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.34.34.70 ※ 編輯: xiphoid 來自: 1.34.34.70 (06/20 20:02)

06/20 22:51, , 1F
為什麼要多加個_view呢?? 的確抓到滿多東西的,可以跟我解
06/20 22:51, 1F

06/20 22:51, , 2F
釋是什麼原因呢?? 謝謝
06/20 22:51, 2F
你用原本網址似乎有抓到東西? 但我result是'' 少了_view 右邊的結果放在iframe裡 不能直接document.getXXX 要用下面的方式才能取得iframe裡的內容 document.querySelector('iframe').contentDocument .getElementById('myP').innerHTML 兩行連起來 (剛剛google的 對DOM不夠熟 囧) ※ 編輯: xiphoid 來自: 1.34.34.70 (06/21 09:20)

06/21 09:44, , 3F
它是顯示一段PyQt .....0x423423(我用print result)就這些
06/21 09:44, 3F

06/21 09:45, , 4F
看來我得去K一下javascript才行
06/21 09:45, 4F
文章代碼(AID): #1FuRlBZB (Python)
文章代碼(AID): #1FuRlBZB (Python)