Selenium查找并更新Web应用程序中的类

huangapple go评论56阅读模式
英文:

Selenium finding and updating class with web app

问题

以下是您的内容的中文翻译:

不久前,我设置了一个使用selenium的Python脚本来爬取网站的脚本。我尝试将这段代码调整为从新网页获取数据,但遇到了问题。问题似乎是页面是一个应用程序,而不是一个更标准的网页(而且我的理解不够充分)。

我似乎试图更新的元素是"ag-paging-number"。我尝试使用click()代替page,但也没有奏效。

最终,该脚本应该循环遍历1496页并保存数据(如果有关如何设置目录的提示,将非常有帮助)。感谢任何帮助。
显然,一旦脚本正常工作,我会切换到无头模式。

英文:

Some time ago I set up a Python script utilizing selenium to crawl across a website. I have tried to adopt the code to get data from a new webpage but have run into trouble. The issue seems to be that the page is an app rather than a more standard page (and my understanding is not ideal).

The element I seem to be trying to update is "ag-paging-number". I tried click() instead of page and this did not work either.

Ulitmately, the script should cycle through the 1496 pages and save down the data (Any tips on how to set the directory would be great). Any help would be appreciated.
Obviously once the script is working I will switch to headless

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import codecs


options = Options()
options.add_argument("--window-size=1920,1200")

driver = webdriver.Chrome()

url = "https://app.climatevaluation.com/apps/projections/table/index.html"
driver.get(url)
for page in range(1,1496,1):
        time.sleep(10)
        try: 
            driver.find_element_by_class_name("ag-paging-number").click()
        except:
            break
with codecs.open('session'+str(page)+'.htm', 'w','utf-8') as out:
         out.write(driver.page_source)
 

答案1

得分: 0

我认为你愿意点击下一页按钮吗?

使用 driver.find_element_by_xpath("//div[@ref='btNext']/span").click()

在循环之前,你可能还想添加 driver.implicitly_wait(10)

英文:

I think you are willing to click the next page button?

Use driver.find_element_by_xpath("//div[@ref='btNext']/span").click()

You might also want to add driver.implicitly_wait(10) before the loop

huangapple
  • 本文由 发表于 2023年5月11日 09:17:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定