0
from splinter import Browser
from splinter.exceptions import ElementDoesNotExist
from selenium import webdriver
from selenium.common.exceptions import WebDriverException

browser.find_by_tag('body').text

browser.visit(str('http://ariismits.com/contact-us'))
a = browser.find_by_tag('body').text
print a

just returns the menus...

"u'HOME | PHILOSOPHY | PORTFOLIO | WHAT WE DO | BLOG | CONTACT\nMap data \xa92017 Google\nTerms of Use\nReport a map error\nMap\nSatellite\n\n\n\n\n\n\nAriiSmits'u'HOME | PHILOSOPHY | PORTFOLIO | WHAT WE DO | BLOG | CONTACT\nMap data \xa92017 Google\nTerms of Use\nReport a map error\nMap\nSatellite\n\n\n\n\n\n\nAriiSmits'"

... but when I visit the page, I can see phone numbers, email addresses, etc

Why isn't that included in the response please?

Axle Max
  • 785
  • 1
  • 14
  • 23

1 Answers1

0

I found a solution. The answer is that the text has to be visible to a human user when the code runs. This website had responsive design and when the window was smaller the text I was looking for was not visible. So when I ran

browser.find_by_tag('body').text

Splinter did not see the text. Even though the text I was looking for was in the HTML it was not visible on screen (due to responsive design), so Splinter (and Selenium works like this too) did not capture the text.

In my case when this ....

browser = Browser('chrome')
browser.visit('http://ariismits.com/contact-us')

it launches a new window on my laptop it is only half screen. Maximising the window and re-running "browser.find_by_tag('body').text" worked as I wanted. See (Manipulating browser (window) size using Splinter) for more on resizing.

I hope that saves someone else some time. :-)

Axle Max
  • 785
  • 1
  • 14
  • 23