V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
billgreen1
V2EX  ›  Python

<web scraping with Python > 示例代码不工作。

  •  
  •   billgreen1 · 2017-04-18 10:20:19 +08:00 · 1711 次点击
    这是一个创建于 2558 天前的主题,其中的信息可能已经有所发展或是发生改变。
    
    from selenium import webdriver
    from selenium.webdriver.remote.webelement import WebElement
    from selenium.webdriver import ActionChains
    driver = webdriver.PhantomJS()
    driver.get('http://pythonscraping.com/pages/javascript/draggableDemo.html')
    
    print(driver.find_element_by_id("message").text)
    
    element = driver.find_element_by_id("draggable")
    target = driver.find_element_by_id("div2")
    actions = ActionChains(driver)
    actions.drag_and_drop(element, target).perform()
    
    
    print(driver.find_element_by_id("message").text)
    

    预期结果是:两次 print 结果不一样,书上也说不一样。但是我运行是一样的。 我的环境是 python3.5, selenium 3.3 , phantomjs 2.1.1

    2 条回复    2017-04-19 12:55:44 +08:00
    zsz
        1
    zsz  
       2017-04-18 22:38:21 +08:00
    一不一样取决于页面给的内容,你对比抓取下来的内容,是否和在页面看到的一样,一样就是成功了,不必纠结
    billgreen1
        2
    billgreen1  
    OP
       2017-04-19 12:55:44 +08:00
    @zsz 谢谢, 主要是 drag_and_drop 不工作,手动 drag and drop , print 结果是变的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   952 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:49 · PVG 03:49 · LAX 12:49 · JFK 15:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.