PhantomJS 상용 설정

1944 단어 python파충
다음은 PhantomJS 에 관 한 학습 사이트 입 니 다.
PhantomJS 공식 주소:http://phantomjs.org/ PhantomJS 공식 API:http://phantomjs.org/api/ PhantomJS 공식 예시:http://phantomjs.org/examples/PhantomJS GitHub:https://github.com/ariya/phantomjs/ 중국어:https://selenium-python-zh.readthedocs.io/en/latest/index.html
'''
    : http://phantomjs.org/api/command-line.html

    --disk-cache=[true|false]       
    --ignore-ssl-errors=[true|false]     ssl  ,    https   ,    
    --load-images=[true|false]        
    --proxy=address:port           
'''
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.common import desired_capabilities

#     
headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
    "Accept-Language": "zh-CN,en,*", 
    "Accept-Charset": "utf-8",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"    
    }
for key in headers:
    webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.{}'.format(key)] = headers[key]
    
proxy = Proxy( {
    'proxyType':ProxyType.MANUAL,
    'httpProxy':'212.90.168.150:52589'
} )
desired_capabilities = desired_capabilities.DesiredCapabilities.PHANTOMJS.copy()
#   ip      
proxy.add_to_capabilities(desired_capabilities)

#      
desired_capabilities["phantomjs.page.settings.loadImages"]=False

#    cookie
desired_capabilities["phantomjs.page.customHeaders.Cookie"]='_gauges_unique_month=1; …ear=1; _gauges_unique=1'

browser = webdriver.PhantomJS( desired_capabilities=desired_capabilities )
url=u'http://httpbin.org/get'
browser.get(url)
print(  browser.page_source)
browser.close()
browser.quit()

좋은 웹페이지 즐겨찾기