Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 幻影不';t使用window.scollTo向下滚动_Javascript_Python_Selenium_Web Scraping_Phantomjs - Fatal编程技术网

Javascript 幻影不';t使用window.scollTo向下滚动

Javascript 幻影不';t使用window.scollTo向下滚动,javascript,python,selenium,web-scraping,phantomjs,Javascript,Python,Selenium,Web Scraping,Phantomjs,因此,我使用selenium/phantomjs中最基本的方法来执行向下滚动操作。 代码似乎都很好,但不起作用。 我试着打印“document.body.scrollHeight”,每次滚动后都保持不变。(例如,高度保持在10532) 我正在浏览某个人的twitter页面,比如“twitter.com/XXXXX” 谁能给我一个提示,我在这里能做些什么 我使用的Web驱动程序是phantomjs 代码如下: def getfullpage(url): print "getting ful

因此,我使用selenium/phantomjs中最基本的方法来执行向下滚动操作。 代码似乎都很好,但不起作用。 我试着打印“document.body.scrollHeight”,每次滚动后都保持不变。(例如,高度保持在10532)

我正在浏览某个人的twitter页面,比如“twitter.com/XXXXX”

谁能给我一个提示,我在这里能做些什么

我使用的Web驱动程序是phantomjs

代码如下:

def getfullpage(url):
    print "getting fullpage..."
    driver.get(url)
    time.sleep(2)
    reloads = 3000
    pause = 0
    driver.save_screenshot("what'shappening.jpg")
    for times in range(reloads):
        driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
        time.sleep(pause)
        newheight = driver.execute_script("return document.body.scrollHeight")
        print newheight
    page = driver.page_source.encode("utf-8","ignore")
    return page

我将等待滚动高度增加,并改用
document.documentElement.scrollHeight

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.PhantomJS()
wait = WebDriverWait(driver, 20)

driver.get("https://twitter.com/barackobama")
time.sleep(1)

# scroll the height
height = driver.execute_script("var h=document.documentElement.scrollHeight; window.scrollTo(0, h); return h;")

# wait for the scroll height to increase
wait.until(lambda drv: drv.execute_script("return document.documentElement.scrollHeight;") > height)

# display the final scroll height
print driver.execute_script("return document.documentElement.scrollHeight;")

你检查过phantomjs是否有卷轴吗?当然无头浏览器不会滚动…谢谢你的帮助!我尝试了这种方法,但没有得到更好的结果,我尝试提高等待时间到60秒,但它仍然提高超时异常。我看了截图,一切都很好,它在正确的页面上。它所要做的就是向下滚动,但它没有。我相信我的网络连接是好的。非常奇怪的问题。虽然这个例子中的页面是不可滚动的,但它对我来说很好。我已经用一个较长的页面更新了URL。