# -*- coding: utf-8 -*
import scrapy
import os
from selenium import webdriver
import time
def get_path():
path = os.path.abspath(
os.path.join(
os.path.dirname(
os.path.abspath(__file__)),
os.path.pardir))
return os.path.join(
path, 'tool/phantomjs-2.1.1-linux-x86_64/bin/phantomjs')
browser = webdriver.PhantomJS(get_path())
browser.get('http://www.chinaccm.com/37/372002list.shtml')
elem = browser.find_element_by_id('keyword')
elem.clear()
time.sleep(1)
elem.send_keys('針葉漿'.decode('utf-8'))
browser.find_element_by_xpath(
'//div[@class="search0013"]').click()
time.sleep(1)
print('----------------------{}'.format(browser.current_url))
輸出---------------------- http://www.chinaccm.com/37/372002list.shtmlPhantomJS沒有跳到下一個頁面在Python硒
點擊似乎沒有工作 但是當我使用的chromedriver,它的工作原理
# -*- coding: utf-8 -*
import scrapy
import os
from selenium import webdriver
import time
def get_path():
path = os.path.abspath(
os.path.join(
os.path.dirname(
os.path.abspath(__file__)),
os.path.pardir))
return os.path.join(
path, 'tool/chromedriver')
browser = webdriver.Chrome(get_path())
browser.get('http://www.chinaccm.com/37/372002list.shtml')
elem = browser.find_element_by_id('keyword')
elem.clear()
time.sleep(1)
elem.send_keys('針葉漿'.decode('utf-8'))
browser.find_element_by_xpath(
'//div[@class="search0013"]').click()
time.sleep(1)
print('----------------------{}'.format(browser.current_url))
輸出是 ---------------------- http://www.chinaccm.com/WebInfoList.aspx?start_date=2016-5-9&end_date=2017-5-9&keyword=%E9%92%88%E5%8F%B6%E6%B5%86&Column=372002
嘗試在點擊'driver.save_screenshot('screen_hires.png')'之前保存phantomjs的屏幕截圖,當解析度不同導致某些元素隱藏在某個下拉列表中時,我曾經遇到過它(因爲phantomjs默認爲移動視圖)。如果是這樣,你可以使用'driver.set_window_size(1400,1000)' –