安裝spynner 躺槍

src/png_io.c:3:17: fatal error: png.h: No such file or directory

 #include <png.h>

                 ^

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1javascript


################ sudo apt-get install libpng12-devhtml


from PyQt4 import QtCorejava

ImportError: /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so: undefined symbol: PyUnicodeUCS2_AsUTF8Stringpython


########## pip install pyside
linux

 pip install pyside
報錯:
error: Failed to find cmake. Please specify the path to cmake with --cmake parameter web

############sudo  apt-get install cmakeajax

########## pip install pysidepython2.7


def u(s):
    return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")

修改成ide

def u(s):
    try:
        return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
    except TypeError as e:
        if "decoding Unicode is not supported" in str(e):
            return unicode(s.replace(r'\\', r'\\\\'))

Changing installation method.url

  1. Install Python

  2. Download setuptools, spynner

  3. Install setuptools using ez_setup.py

  4. Install spynner

  5. Install PyQt4

Maybe PyQt4 should be installed at last


#-*- encoding: utf-8 -*-
import spynner
import sys
reload(sys)
sys.setdefaultencoding('gbk')

if __name__ == "__main__": 
browser = spynner.Browser() 

#註釋如下語句就是不打開窗口了
browser.show() 
try: 
browser.load(url='http://www.lpfrx.com', load_timeout=120, tries=1) 
except spynner.SpynnerTimeout: 
print 'Timeout.' 
else: 

browser.wk_fill('input[id="s"]', 'delphi') 
browser.wait(3)

#用javascript提交結果
browser.runjs("document.forms[0].submit();")

#另外一種點擊方式
#browser.wk_click('a[href]',wait_load=True, timeout=8)
browser.wait(3)

//如下是獲取超連接的元素,在第6個連接點擊
bb = browser.webframe.findAllElements('a') 
print len(bb)
print sys.getdefaultencoding()

anchor = bb[6]
try:
browser.wk_click_element_link(anchor, timeout=5)
except spynner.SpynnerTimeout:
print "timeou 5"


browser.wait(5) 
html = browser.html 
if html: 
html = html.encode('utf-8') 
open('lpfrx.txt', 'w').write(html) 
browser.close()
不一樣的方式點擊方式,其實還能夠有其它方式,不過spynner中文資料好少,這東西作爬蟲有點慢,不過能夠訪問那些用ajax方式生成的網頁,很是不錯,模擬登陸和填數據不錯,比經過com口調用IE方便.

相關文章
相關標籤/搜索