推荐学习书目
› 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 · Apr 18, 2017 · 2524 views
    This topic created in 3457 days ago, the information mentioned may be changed or developed.
    
    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 replies  •  2017-04-19 12:55:44 +08:00
    zsz
        1
    zsz  
       Apr 18, 2017
    一不一样取决于页面给的内容,你对比抓取下来的内容,是否和在页面看到的一样,一样就是成功了,不必纠结
    billgreen1
        2
    billgreen1  
    OP
       Apr 19, 2017
    @zsz 谢谢, 主要是 drag_and_drop 不工作,手动 drag and drop , print 结果是变的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2245 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:33 · PVG 19:33 · LAX 04:33 · JFK 07:33
    ♥ Do have faith in what you're doing.