1 from splinter.browser import Browser
 2 with Browser() as b:
 3     for url,name in web:
 4         b.visit(url)
 5         b.fill('Password','password')
 6         button=b.find_by_id('loginBtn')
 7         button.click()
 8         t=b.find_by_id('FreeSpaceId')
 9         print name,t.text
10     tab=b.find_by_id('login-table')
11     ti=tab.first.find_by_xpath('tbody/tr/td/input')
12     ti[0].fill('username')
13     ti[1].fill('password')
14     button=b.find_by_text('Login')
15     button.click()

firefox代理

driver:https://github.com/mozilla/geckodriver/releases

1 proxy_settings={'network.proxy.type': 1,
2 'network.proxy.no_proxies_on':'172.0.0.0/8,10.0.0.0/8,localhost,127.0.0.0/8,::1',
3 'network.proxy.http':'172.1.1.1','network.proxy.http_port':8080,
4  'network.proxy.ssl':'172.1.1.1','network.proxy.ssl_port':8080}
5 b=Browser('firefox',profile_preferences=proxy_settings)

chrome代理

driver:http://chromedriver.storage.googleapis.com/index.html

https://sites.google.com/a/chromium.org/chromedriver/-

 1 from splinter.driver.webdriver.chrome import Options, Chrome
 2 chrome_options = Options()
 3 chrome_options.add_argument('--proxy-server=http://%s' % PROXY)
 4 b=Browser('chrome');b.driver=Chrome(chrome_options=chrome_options)
 5 #--no-proxy-server
 6 #--proxy-auto-detect
 7 #--proxy-server=<scheme>=<uri>[:<port>][;...] | <uri>[:<port>] | "direct://"
 8 ##--proxy-server="http=foopy:80;ftp=foopy2" 
 9 ##--proxy-server="foopy:8080"
10 ## --proxy-server="direct://" will cause all connections to not use a proxy.
11 #--proxy-bypass-list=(<trailing_domain>|<ip-address>)[:<port>][;...]
12 ##--proxy-server="foopy:8080" --proxy-bypass-list="*.google.com;*foo.com;127.0.0.1:8080"
13 #--proxy-pac-url=<pac-file-url>
14 
15 #selenium
16 from selenium import webdriver
17 
18 PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT
19 
20 chrome_options = webdriver.ChromeOptions()
21 chrome_options.add_argument('--proxy-server=http://%s' % PROXY)
22 
23 chrome = webdriver.Chrome(chrome_options=chrome_options)
24 chrome.get("http://whatismyipaddress.com")

如使用

b=Browser('chrome',chrome_options=chrome_options)

需要修改库中的chrome.py

        if 'chrome_options' in kwargs:
            options = kwargs.get('chrome_options', Options())
            del kwargs['chrome_options']
        else:
            options = Options()

 

posted on 2015-12-23 11:45  perel  阅读(1101)  评论(0编辑  收藏  举报