Python Selenium脚本中等rss提要

2024-04-26 23:21:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用python和selenium编写一些博客。在

但是,源页面仅限于几篇文章,因此我需要向下滚动以加载AJAX。。在

有没有一种方法可以在一次调用selenium时获得完整的源代码?在

代码应该是:

        # url and page source generating
        url = url_constructor_medium_news(blog_name)
        content = social_data_tools.selenium_page_source_generator(driver, url)
        try:
            # construct soup
            soup = BeautifulSoup(content, "html.parser").rss.channel
            # break condition
            divs = soup.find_all('item')
        except AttributeError as e:
            print(e.__cause__)

        # friendly
        time.sleep(3 + random.randint(1, 5))

Tags: and方法代码urlsource源代码selenium文章
1条回答
网友
1楼 · 发布于 2024-04-26 23:21:56

我不相信有一种方法可以用卸载的数据填充驱动程序,否则这些数据将通过滚动获得。在

获取数据的另一种解决方案是driver.execute_script("windows.scrollTo(0, document.body.scrollHeight);")

我以前用this作为参考。在

我希望这有帮助!在

相关问题 更多 >