【问题标题】:Why doesn't this Python Splinter call return all the body text?为什么这个 Python Splinter 调用不返回所有正文?
【发布时间】:2017-10-10 16:09:06
【问题描述】:
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

只返回菜单...

"u'HOME | 哲学 | 作品集 | 我们做什么 | 博客 | 联系方式\n地图数据 \xa92017 Google\n使用条款\n报告地图错误\n地图\n卫星\n\n\n\n\n\n \nAriiSmits'u'HOME | 理念 | 作品集 | 我们做什么 | 博客 | 联系方式\n地图数据 \xa92017 Google\n使用条款\n报告地图错误\n地图\n卫星\n\n\n\n\n\n\ nAriiSmits'"

...但是当我访问该页面时,我可以看到电话号码、电子邮件地址等

为什么没有包含在响应中?

【问题讨论】:

    标签: python python-2.7 parsing splinter


    【解决方案1】:

    我找到了解决方案。答案是在代码运行时文本必须对人类用户可见。该网站采用响应式设计,当窗口较小时,我正在寻找的文本不可见。所以当我跑的时候

    browser.find_by_tag('body').text
    

    Splinter 没有看到文本。尽管我正在寻找的文本在 HTML 中,但它在屏幕上不可见(由于响应式设计),所以 Splinter(和 Selenium 也这样工作)没有捕获文本。

    在我的情况下......

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

    它会在我的笔记本电脑上启动一个新窗口,它只有半屏。最大化窗口并重新运行“browser.find_by_tag('body').text”按我的意愿工作。有关调整大小的更多信息,请参阅 (Manipulating browser (window) size using Splinter)。

    我希望这可以节省其他人一些时间。 :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      相关资源
      最近更新 更多