单击按钮后,Selenium 获取 http 请求 ajax url
Selenium get http request ajax url after button click
我需要在以编程方式单击网页中的按钮时获取 http 请求 URL。
我正在使用 selenium 来跟踪按钮,并且正在执行单击按钮。单击按钮时,它会发出一个 http 请求,同样可以在浏览器的网络选项卡中进行跟踪。
如何在使用 selenium 触发按钮点击后以编程方式获取请求 URL。
我可以用来实现相同功能的任何其他工具或库对我来说也可以。我只需要能够在以编程方式单击按钮后获得 URL 。这是一个动态的 URL,它会定期更改,objective 是通过代码自动执行下载过程。
在此先感谢您的帮助!
您可以使用JavaScript执行器获取网络数据。请参考
从那里获取 request/response 数据。
DesiredCapabilities d = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
d.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
WebDriver driver = new ChromeDriver(d);
driver.get("https://www.google.co.in/");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
LogEntries les = driver.manage().logs().get(LogType.PERFORMANCE);
for (LogEntry le : les) {
System.out.println(le.getMessage());
}
Python 等价于:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import
DesiredCapabilities
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get('https://whosebug.com')
for entry in driver.get_log('performance'):
print(entry)
请参阅线程以获取更多信息python
我需要在以编程方式单击网页中的按钮时获取 http 请求 URL。 我正在使用 selenium 来跟踪按钮,并且正在执行单击按钮。单击按钮时,它会发出一个 http 请求,同样可以在浏览器的网络选项卡中进行跟踪。
如何在使用 selenium 触发按钮点击后以编程方式获取请求 URL。
我可以用来实现相同功能的任何其他工具或库对我来说也可以。我只需要能够在以编程方式单击按钮后获得 URL 。这是一个动态的 URL,它会定期更改,objective 是通过代码自动执行下载过程。
在此先感谢您的帮助!
您可以使用JavaScript执行器获取网络数据。请参考
DesiredCapabilities d = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
d.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
WebDriver driver = new ChromeDriver(d);
driver.get("https://www.google.co.in/");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
LogEntries les = driver.manage().logs().get(LogType.PERFORMANCE);
for (LogEntry le : les) {
System.out.println(le.getMessage());
}
Python 等价于:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import
DesiredCapabilities
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get('https://whosebug.com')
for entry in driver.get_log('performance'):
print(entry)
请参阅线程以获取更多信息python