如何点击 Google Trends 中的“加载更多”按钮并通过 Selenium 和 Python 打印所有标题

2024-05-03

这次我想单击一个按钮来加载更多实时搜索。这是网站的链接:

该按钮位于页面末尾,代码如下:

<div class="feed-load-more-button" ng-if="ctrl.shouldShowLoadingMoreItemsSpinner()" ng-click="ctrl.loadMoreFeedItems()" role="button" tabindex="0" style="">
Load more
</div>

由于涉及到一些 AngularJS,我不知道该怎么做...... 有什么提示/帮助吗?

感谢你们, 琼


点击LOAD MORE按钮加载更多实时搜索,然后打印它们,您可以使用以下解决方案:

  • 代码块:

    # -*- coding: UTF-8 -*-
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.common.exceptions import TimeoutException
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_argument('disable-infobars')
    driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://trends.google.com/trends/trendingsearches/realtime?geo=AR&category=all")
    myLength = len(WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='title']"))))
    
    while True:
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        try:
            WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='feed-load-more-button'][@ng-click=\"ctrl.loadMoreFeedItems()\"]"))).click()
            WebDriverWait(driver, 20).until(lambda driver: len(driver.find_elements_by_xpath("//div[@class='title']")) > myLength)
            titles = driver.find_elements_by_xpath("//div[@class='title']")
            myLength = len(titles)
        except TimeoutException:
            break
    
    for title in titles:
        print(title.text)
    driver.quit()
    
  • 控制台输出:

    Nikola Kalinic • 2018 World Cup • Zlatko Dalic
    Vicentico • Valeria Bertuccelli • Florián Fernandez Capello
    Mauricio Macri • Juan José Aranguren • Argentina • Jorge Lanata
    Goalkeeper • 2018 World Cup • Mohamed El-Shenawy • Ahmed El-Shenawy
    Argentina • Manuel Belgrano • María Josefa Ezcurra • Mercedes Tomasa de San Martín y Escalada
    South Korea national football team • Russia • Zlatan Ibrahimovic
    Italian nationality law • Mar del Plata
    Hirving Lozano • 2018 World Cup • Earthquake
    Central Bank of Argentina • Luis Caputo • Federico Sturzenegger • Nicolás Dujovne
    Porsche Mission E • Electric vehicle • Car • Electric car
    Intelligence • Intelligence quotient • Research
    Call for bids • National Flag Memorial • Monument • Rosario • Pablo Javkin
    Journalist • Club Atlético Belgrano • Córdoba • Manuel Belgrano
    France • Spain • Immigration
    Natti Natasha • Zum Zum • Daddy Yankee • R.K.M & Ken-Y • Francisco José Arcángel Ramos
    Mercosur • Pacific Alliance • Pact • Paraguay
    World Cup • England national football team • Romelu Lukaku • Dries Mertens
    House arrest • Detention • Robbery
    Argentina • Emerging markets • MSCI • Market • Finance • Morgan Stanley
    Eurozone • Budget • France • Bruno Le Maire • Germany • Finance
    Intelligence • Intelligence quotient • Research
    Brazil national football team • Tite • Philippe Coutinho • Rostov Arena
    2018 World Cup • Aleksandar Kolarov • Guillermo Ochoa
    2018 World Cup • Spain
    Sloth • Giant ground sloth • Fossil • San Pedro
    Government • Inflation • Alfredo Cornejo • Mendoza • Ministry of Finance
    Corrientes • Cannabis • Tractor • Argentine Naval Prefecture
    Argentine Chamber of Deputies • Chubut Province • Peronism • Front for Victory
    Jorge Rial • Father's Day • Intrusos en el espectáculo
    Debt • Debt relief • Refinancing • Chaco Province
    Polygraph
    Malaria • Paraguay • Americas
    General Confederation of Labour • Unemployment • Trade union
    Earthquake • Japan
    Angela Merkel • Europe • Germany • Emmanuel Macron • European Union
    Colombia • Ivan Duque • Gustavo Petro
    Lynx • Wildcat • Cat
    Rafael Márquez • 2018 World Cup • Antonio Carbajal
    Superior Council for Private Enterprise • Nicaraguan Social Security Institute
    2018 World Cup • William Kvist • Jefferson Farfán
    La Plata • Controlled-access highway • Buenos Aires Province • Ensenada
    Leonardo Mayer • Kevin Anderson • ATP World Tour 500 series • Association of Tennis Professionals
    Cristiano Ronaldo • 2018 World Cup • Spain
    Casino • Mendoza • Hyatt
    Mauricio Macri • Jorge Lanata • Argentina • Alejandro Wiebe
    Drug
    Buenos Aires Province • Judiciary
    2018 World Cup • Lionel Messi • Russia • Diego Maradona • Mario Kempes
    Santiago • Natural environment • Air pollution
    Chimbas Department
    Chaco Province • Judiciary • Unemployment
    Hailey Rhode Baldwin • Justin Bieber
    2018 World Cup • Russia
    Mauricio Macri • Luis Caputo • Politician • Argentine Chamber of Deputies
    Trade war • Agriculture • Donald Trump • China
    2018 World Cup • Dennis te Kloese • Juan Carlos Osorio
    Aaron Ramsey • 2018 World Cup • Arsenal F.C. • Football player • Gareth Bale
    2018 World Cup • Aleksandar Kolarov
    Iñaki Urdangarin • Cristina Federica, Infanta of Spain • Spain • Luis Roldán
    Argentina • Electric car
    San Lorenzo de Almagro • Liga Nacional de Básquet • Corrientes
    Christina Aguilera • Jimmy Fallon • Liberation • New York City
    Intelligence quotient • Intelligence • Flynn effect • Research
    María Eugenia Vidal • Republican Proposal • Horacio Rodríguez Larreta
    Natural environment • Pollution • Plastic pollution
    Funding • International Finance Corporation • World Bank • Córdoba
    Face • Zygomatic bone • Rosario
    Cristóbal López • Administración Federal de Ingresos Públicos • Ricardo Echegaray
    Club Atlético Belgrano • Lucas Bernardi • Superliga Argentina de Fútbol
    Juan José Aranguren • Mauricio Macri • Energy • YPF
    Greater Buenos Aires • Motor coach
    Stranger Things • MTV Movie & TV Awards
    Peru • Lima • Earthquake • 2018 World Cup • Geophysics Institute of Peru
    Juan Carlos Osorio • 2018 World Cup
    2018 World Cup • Player • Russia • Lionel Messi
    Raffaella Carrà
    America's Got Talent • Janis Joplin • Howie Mandel
    Homicide • Detention
    La Plata • Julio Garro • Víctor Manuel Fernández • María Eugenia Vidal
    Mariano Arcioni • Chubut Province • Payment
    Angela Merkel • Horst Seehofer • Germany • Government • Human migration
    Israel • Benjamin Netanyahu • Syria • Iran • Ali Khamenei • Vladimir Putin
    Yerba mate • Cannabis • Lomas de Zamora • Detention • Mate
    Senate • Argentine Chamber of Deputies
    2010 FIFA World Cup • South Africa
    Handball • Chile • Argentina national football team
    2018 World Cup • Russia • Terrorism • Attack
    Abortion • Conscientious objector
    Rosario • Trade
    Natalie Weber • Mauro Zárate • Pampita
    Water • Cipolletti • Pressure • Cleaning
    Chimbas
    NATO • Military exercise • Russia
    Federico Sturzenegger • Economist • Argentina • Arnaldo Bocco • Martín Redrado
    Nolle prosequi
    2018 World Cup • Russia • Paolo Guerrero • Christian Cueva
    Ricardo Darín • Valeria Bertuccelli • Érica Rivas
    Joachim Löw • 2018 World Cup
    Israel • Golan Heights • Syria • Donald Trump
    Meningitis • Bacteria • Salta • Streptococcus pneumoniae
    ANSES • Subsidy
    Argentine Chamber of Deputies • Radical Civic Union • Cambiemos •
    Martín Demichelis • 2018 World Cup • Russia
    Santiago de Compostela • Pilgrim • Galicia • Spain
    Refugee • Pope Francis • Human migration
    Stranger Things • Father's Day • Joe Keery
    Ivan Duque • President of Colombia • Latin America
    General Confederation of Labour • Unemployment • General strike • Buenos Aires Province
    Juan Carlos Osorio • Faustino Asprilla • 2018 World Cup
    Germán Burgos • Club Atlético River Plate • Diego Simeone • Atlético Madrid
    Nissan Navara • Pickup truck • Automotive industry
    Baobab • Research • Tree
    Susana Giménez • Alejandro Wiebe • Argentina • Telefe
    Wanda Nara • Maxi López • Mauro Icardi
    Damir Skomina • 2018 World Cup • Colombia • Referee • Russia • Mehdi Abid Charef
    Diabetes mellitus • Visual perception • Diabetic retinopathy
    Berisso • Threat • La Plata • Search and seizure • School
    Game of Thrones • HBO • San Diego Comic-Con • Spin-off • George R. R. Martin
    Argentina • Duet • Traveling Wilburys
    Blood donation • Uruguay • Maldonado
    2018 World Cup Group F • Mexico • Hirving Lozano
    Colombian presidential election, 2018 • Colombia • Juan Manuel Santos
    Colombia national football team
    Desertification • United Nations Convention to Combat Desertification
    Saski Baskonia • Liga ACB • Pablo Laso • Real Madrid C.F.
    Rosario de la Frontera • Salta • Spa town
    Neymar • 2018 World Cup • Philippe Coutinho • Tite • Russia
    Pocito Department
    Argentine peso • Depreciation • Central Bank of Argentina
    San Salvador de Jujuy • Buenos Aires International Book Fair • Fair •
    Córdoba • Shock
    Iceland • Immigration • Icelanders
    Mirtha Legrand
    Traffic collision • Wound
    2018 World Cup • Russia • Vikings
    Mauricio Macri • Businessperson • Argentina • Economic development
    Ricardo Darín • Valeria Bertuccelli • Érica Rivas • Vicentico
    María Eugenia Vidal • Martiniano Molina • Quilmes
    Argentina women's national field hockey team • Julieta Jankunas • Argentina
    Prince Harry • Catherine, Duchess of Cambridge • British royal family
    Sergej Milinkovic-Savic • SS Lazio • 2018 World Cup
    Organ donation • Organ • Organ transplantation
    Sex education • San Fernando del Valle de Catamarca • Argentine Chamber of Deputies
    Margarita Stolbizer • Sergio Massa • Peronism • Justicialist Party • Elisa Carrió
    Google Maps • Waze • Information • Radar
    Locomotive • Japan
    Spain • Human migration • Immigration • France • Valencia • Carmen Calvo Poyato
    Joaquín Sabina • Madrid
    Jorge Lorenzo • Marc Márquez • MotoGP • Dani Pedrosa
    Manuel Belgrano
    2018 World Cup • Russia • Mohamed Salah • Denis Cheryshev
    María Eugenia Vidal • Teacher
    Remand
    Magistrate • Judiciary • Research
    Laura Bush • Donald Trump • Immigration • George W. Bush • Melania Trump
    Sebastián Piñera • Chile • Michelle Bachelet
    School • Gender identity • Discrimination • National Institute Against Discrimination, Xenophobia and Racism
    Engineering • San Miguel de Tucumán
    School • Buenos Aires Province • Tariff
    Edgardo Bauza • Rosario Central • Marco Ruben • Rosario
    Bicameralism
    Russia • 2018 World Cup • Lionel Messi
    Rawson Department, San Juan
    El Litoral • Corrientes Province
    Abortion • PH: Podemos hablar • Andy Kusnetzoff • Charlotte Caniggia
    The Shining • Ewan McGregor • Doctor Sleep • Danny Torrance • Stephen King
    Paulo Ferrari • Rosario Central • Rosario • Superliga Argentina de Fútbol
    Carbon monoxide
    Ground frost • Fog • Rain and snow mixed • Cold • Posadas
    Argentine rock • Russia • Luis Alberto Spinetta • Gustavo Cerati • Charly García
    Incredibles 2 • Brad Bird • Pixar
    Carbohydrate • Dieting • Weight loss
    Uber • Mendoza Province • Government • System • Statute
    Paragliding
    Jorge Sampaoli • Pedro Pasculli • 2018 World Cup • Paulo Dybala • Russia
    Posadas • Cold
    Luis Miguel • Mexico
    Unidentified flying object • Russia • Phenomenon
    Lisandro Magallán • Boca Juniors • AFC Ajax • Wílmar Barrios
    Tandil • Fossil • Glyptodon
    Harry Kane • 2018 World Cup • Gareth Southgate
    Light welterweight • Boxing • Almirante Brown Partido • Mariano Cascallares
    New Jersey
    Small and medium-sized enterprises • Argentina • CAME - Argentina Confederation of Medium Enterprises
    Season • Ryan Murphy • American Horror Story: Murder House • Sarah Paulson
    Conflagration • Posadas
    Robot • Old age • China
    2018 World Cup • Russia • Terrorism • Islamic State of Iraq and the Levant
    Christian Cueva • 2018 World Cup
    Argentina national football team • Volleyball • Argentina
    National Electoral Institute • Candidate • National Action Party • Mexico
    Horoscope • Astrological sign
    Mauricio Macri • María Eugenia Vidal • Ensenada • Ambulance • Cambiemos
    Trade • Tax deduction • Debt • Macroeconomics
    Cristiano Ronaldo • Pelé • 2018 World Cup • Miroslav Klose • Uwe Seeler
    Martín Miguel de Güemes • Juan Manuel Urtubey • Salta Province • Argentina
    Compressed natural gas • La Pampa Province • General Pico • Camuzzi Gas Pampeana
    Santa Fe • Provincial Hospital Dr. José María Cullen • Baleada
    National University of La Plata • Vocational school • School • Vocational education
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何点击 Google Trends 中的“加载更多”按钮并通过 Selenium 和 Python 打印所有标题 的相关文章

  • 使用特定的类/函数预加载 Jupyter Notebook

    我想预加载一个笔记本 其中包含我在另一个文件中定义的特定类 函数 更具体地说 我想用 python 来做到这一点 比如加载一个配置文件 包含所有相关的类 函数 目前 我正在使用 python 生成笔记本并在服务器上自动启动它们 因为不同的
  • 如何使用 opencv.omnidir 模块对鱼眼图像进行去扭曲

    我正在尝试使用全向模块 http docs opencv org trunk db dd2 namespacecv 1 1omnidir html用于对鱼眼图像进行扭曲处理Python 我正在尝试适应这一点C 教程 http docs op
  • 将html数据解析成python列表进行操作

    我正在尝试读取 html 网站并提取其数据 例如 我想查看公司过去 5 年的 EPS 每股收益 基本上 我可以读入它 并且可以使用 BeautifulSoup 或 html2text 创建一个巨大的文本块 然后我想搜索该文件 我一直在使用
  • Pandas/Google BigQuery:架构不匹配导致上传失败

    我的谷歌表中的架构如下所示 price datetime DATETIME symbol STRING bid open FLOAT bid high FLOAT bid low FLOAT bid close FLOAT ask open
  • Pandas 日期时间格式

    是否可以用零后缀表示 pd to datetime 似乎零被删除了 print pd to datetime 2000 07 26 14 21 00 00000 format Y m d H M S f 结果是 2000 07 26 14
  • 将 python2.7 与 Emacs 24.3 和 python-mode.el 一起使用

    我是 Emacs 新手 我正在尝试设置我的 python 环境 到目前为止 我已经了解到在 python 缓冲区中使用 python mode el C c C c将当前缓冲区的内容加载到交互式 python shell 中 显然使用了什么
  • 独立滚动矩阵的行

    我有一个矩阵 准确地说 是 2d numpy ndarray A np array 4 0 0 1 2 3 0 0 5 我想滚动每一行A根据另一个数组中的滚动值独立地 r np array 2 0 1 也就是说 我想这样做 print np
  • datetime.datetime.now() 返回旧值

    我正在通过匹配日期查找 python 中的数据存储条目 我想要的是每天选择 今天 的条目 但由于某种原因 当我将代码上传到 gae 服务器时 它只能工作一天 第二天它仍然返回相同的值 例如当我上传代码并在 07 01 2014 执行它时 它
  • 如何在 Python 中解析和比较 ISO 8601 持续时间? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一个 Python v2 库 它允许我解析和比较 ISO 8601 持续时间may处于不同单
  • Python 2:SMTPServerDisconnected:连接意外关闭

    我在用 Python 发送电子邮件时遇到一个小问题 me my email address you recipient s email address me email protected cdn cgi l email protectio
  • Python beautifulsoup 仅限 1 级文本

    我看过其他 beautifulsoup 得到相同级别类型的问题 看来我的有点不同 这是网站 我正试图拿到右边那张桌子 请注意表的第一行如何展开为该数据的详细细分 我不想要那个数据 我只想要最顶层的数据 您还可以看到其他行也可以展开 但在本例
  • Numpy - 根据表示一维的坐标向量的条件替换数组中的值

    我有一个data多维数组 最后一个是距离 另一方面 我有距离向量r 例如 Data np ones 20 30 100 r np linspace 10 50 100 最后 我还有一个临界距离值列表 称为r0 使得 r0 shape Dat
  • 加快网络抓取速度

    我正在使用一个非常简单的网络抓取工具抓取 23770 个网页scrapy 我对 scrapy 甚至 python 都很陌生 但设法编写了一个可以完成这项工作的蜘蛛 然而 它确实很慢 爬行 23770 个页面大约需要 28 小时 我看过scr
  • javascript 是否有等效的 __repr__ ?

    我最接近Python的东西repr这是 function User name password this name name this password password User prototype toString function r
  • 不同编程语言中的浮点数学

    我知道浮点数学充其量可能是丑陋的 但我想知道是否有人可以解释以下怪癖 在大多数编程语言中 我测试了 0 4 到 0 2 的加法会产生轻微的错误 而 0 4 0 1 0 1 则不会产生错误 两者计算不平等的原因是什么 在各自的编程语言中可以采
  • 如何在 pygtk 中创建新信号

    我创建了一个 python 对象 但我想在它上面发送信号 我让它继承自 gobject GObject 但似乎没有任何方法可以在我的对象上创建新信号 您还可以在类定义中定义信号 class MyGObjectClass gobject GO
  • 如何解决 PDFBox 没有 unicode 映射错误?

    我有一个现有的 PDF 文件 我想使用 python 脚本将其转换为 Excel 文件 目前正在使用PDFBox 但是存在多个类似以下错误 org apache pdfbox pdmodel font PDType0Font toUnico
  • 模拟pytest中的异常终止

    我的多线程应用程序遇到了一个错误 主线程的任何异常终止 例如 未捕获的异常或某些信号 都会导致其他线程之一死锁 并阻止进程干净退出 我解决了这个问题 但我想添加一个测试来防止回归 但是 我不知道如何在 pytest 中模拟异常终止 如果我只
  • Pandas 每周计算重复值

    我有一个Dataframe包含按周分组的日期和 ID df date id 2022 02 07 1 3 5 4 2022 02 14 2 1 3 2022 02 21 9 10 1 2022 05 16 我想计算每周有多少 id 与上周重
  • CGImage/UIImage 在 UI 线程上延迟加载会导致卡顿

    我的程序显示一个水平滚动表面 从左到右平铺有 UIImageViews 代码在 UI 线程上运行 以确保新可见的 UIImageView 分配有新加载的 UIImage 加载发生在后台线程上 一切工作几乎都很好 除了每个图像变得可见时出现口

随机推荐