python webkit 异步抓取页面数据

来源:互联网 发布:企业管理的数据意识 编辑:程序博客网 时间:2024/06/04 23:34

http://blog.csdn.net/cabing2005/article/details/9764379

http://nightly.webkit.org/


[python] view plaincopy
  1. #!/usr/bin/python  
  2. from ghost import Ghost  
  3.   
  4.   
  5. class FetcherCartoon:  
[python] view plaincopy
  1. def getCartoonUrl(self, url):  
  2.       
  3.     if url is None:  
  4.         return false  
  5.     #todo many decide about url  
  6.       
  7.     ghost = Ghost()  
  8.     #open webkit  
  9.     ghost.open(url)  
  10.     #exceute javascript and get what you want   
  11.     result, resources = ghost.evaluate("document.getElementById('cp_image').getAttribute('src');")  
  12.     del resources  
  13.     return result  
[python] view plaincopy
  1. if __name__ == "__main__":  
  2.     url = 'http://www.dm5.com/m136836-p3/'  
  3.     result = None  
  4.     fetcher = FetcherCartoon()  
  5.   
  6.   
  7.     result = fetcher.getCartoonUrl(url)  
  8.     print result  

0 0
原创粉丝点击