Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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
在Python和Javascript中使用Selenium在Quora上无限滚动_Javascript_Python_Selenium_Infinite Scroll_Quora - Fatal编程技术网

在Python和Javascript中使用Selenium在Quora上无限滚动

在Python和Javascript中使用Selenium在Quora上无限滚动,javascript,python,selenium,infinite-scroll,quora,Javascript,Python,Selenium,Infinite Scroll,Quora,我试图处理Quora网站中的“无限滚动”。 在尝试使用send_keys方法之后,我将selenium lib与Python结合使用,我尝试运行Javascript命令以便向下滚动页面 当我运行代码时,它不起作用,但是如果我尝试在firefox控制台中运行,它就起作用了。 我如何解决这个问题?有可能使用幻影 def scrapying(self): print platform.system() browser = webdriver.Firefox()

我试图处理Quora网站中的“无限滚动”。 在尝试使用send_keys方法之后,我将selenium lib与Python结合使用,我尝试运行Javascript命令以便向下滚动页面

当我运行代码时,它不起作用,但是如果我尝试在firefox控制台中运行,它就起作用了。 我如何解决这个问题?有可能使用幻影

def scrapying(self):
    print platform.system()

        browser = webdriver.Firefox()
        #browser = webdriver.PhantomJS(executable_path='/usr/local/bin/node_modules/phantomjs/lib/phantom/bin/phantomjs')

    browser.get("https://www.quora.com/C-programming-language")
    #browser.get("https://answers.yahoo.com/dir/index?sid=396545660")
    time.sleep(10)

    #elem = browser.find_element_by_class_name("topic_page content contents main_content fixed_header ContentWrapper")
    no_of_pagedowns = 500

    while no_of_pagedowns:
        #elem.send_keys(Keys.SPACE)
        browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(0.5)
        no_of_pagedowns -= 1

    browser.quit()






myClassObject = getFrom()
myClassObject.scrapying()

其中一个选项是递归地删除页面上最后一次加载的帖子:

从selenium导入webdriver
driver=webdriver.Chrome()
驱动程序。获取(“https://www.quora.com/C-programming-language")
职位数量=200
posts=驱动程序。通过css选择器(“div.pagedlist\u项”)查找元素
而len(posts)

它会向下滚动页面,直到至少加载了
NUM_POSTS
POSTS。

其中一个选项是递归地加载页面上最后加载的post:

从selenium导入webdriver
driver=webdriver.Chrome()
驱动程序。获取(“https://www.quora.com/C-programming-language")
职位数量=200
posts=驱动程序。通过css选择器(“div.pagedlist\u项”)查找元素
而len(posts)

它会向下滚动页面,直到至少加载了
NUM_POSTS
POSTS。

在使用Firefox时,我也无法使用它触发无限滚动。代码的要点在控制台中起作用,但是:

for i in range(0, 5):
    self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)

在使用Firefox时,我也无法使用它触发无限滚动。代码的要点在控制台中起作用,但是:

for i in range(0, 5):
    self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(3)

你对quora上的哪个页面感兴趣?谢谢。对不起,我现在编辑代码。我感兴趣的是这一页quora上的哪一页你对滚动感兴趣?谢谢。对不起,我现在编辑代码。我感兴趣的页面是我尝试运行代码的页面,但在firefox或终端中的字符串中,我没有收到任何反馈。你使用类似Chrome的驱动程序?但是firefox js功能?@RedVelvet好的,你能在Chrome上试试吗?是的,你明白了!它可以与chrome一起使用,但是为什么不能在firefox上使用,以及如何在phantomJs上尝试同样的东西对我的项目来说更重要。我尝试使用time.sleep(3)too我尝试运行此代码,但在firefox或终端中的字符串中,我没有收到任何反馈。你使用类似Chrome的驱动程序?但是firefox js功能?@RedVelvet好的,你能在Chrome上试试吗?是的,你明白了!它可以与chrome一起使用,但是为什么不能在firefox上使用,以及如何在phantomJs上尝试同样的东西对我的项目来说更重要。我试着利用时间。睡觉也一样