1. 程式人生 > >Scrapy selenium 設置頭部信息headers-------UA

Scrapy selenium 設置頭部信息headers-------UA

blog screens mon use headers setting log settings browser

1,PhantomJS

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap[‘phantomjs.page.settings.userAgent‘] = ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36‘
browser = webdriver.PhantomJS(desired_capabilities=dcap)
browser.save_screenshot(‘ctrip.png‘)(你可以截圖下來看看你是不是正常訪問頁面數據)

2,Chrome

將上面的PhantomJS替換掉就可以。

Scrapy selenium 設置頭部信息headers-------UA