It's a story now.
I want the width (px) of the div. You can easily get it on the browser side using JS, but this time I want it on the server side. Since it is the width of the div, it may be decided after rendering. So render on the server side. I used to do something with Selenium by putting Firefox on the server, but when installing Firefox, I have a memory that I want to spend time around the display, so this time I tried using PhantomJS as a browser.
http://phantomjs.org/
PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
That's right. amazing.
Build PhantomJS just like this
http://phantomjs.org/build.html
Maybe because the server this time was CentOS5, it didn't work, and I changed it to git checkout 1.9
and it went smoothly. I'm in a hurry, so is this okay for the time being ...
Next, I want to hit this from Selenium
pip install selenium
from selenium import webdriver
url = 'http://hoge'
driver = webdriver.PhantomJS()
driver.get(url)
e = driver.find_element_by_xpath("//*[@class='hoge']")
print(e.size)
>>> {'width': 602, 'height': 2098}
It seems to be good because it was the display result on my Chrome. The end
Recommended Posts