我想从 https 响应中获取数据,但它们的数据只有在单击打开对话框窗口的按钮后才会出现(查看下面的屏幕),所以我必须打开所有必要的窗口,然后运行 request.get。主要困难是我不明白如何为我运行 driver.get 命令的同一窗口制作 request.get 。import requestsfrom selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECchrome_options = webdriver.ChromeOptions()chrome_options.add_argument("start-maximized")driver = webdriver.Chrome(options=chrome_options)driver.get(url)XPATH = "//*[name()='svg' and contains(@class, 'jss350')]"XPATH2 = '/html/body/div[3]/div[3]/div/div[3]/button/span[1]'# Wait for all svg elements to be clickableWebDriverWait(driver, 20).until(EC.presence_of_all_elements_located((By.XPATH, XPATH)))# find list of svg elementssvg_elements = driver.find_elements_by_xpath(XPATH)for element in svg_elements[3:4]: element.click() #open windows WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, XPATH2))).click() #close#here is I want to run the request.get function to grab data from the same windowdriver.quit()params = { 'products': 'RU',}url = 'my url'r = requests.get(url, params=params, headers={ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36'})json_data = r.json()print(r.url)print(r.text)
1 回答
MM们
TA贡献1886条经验 获得超2个赞
api 可以独立于 UI 操作(硒自动化)工作。这意味着您可以在 POST 或 Get 中传递必要的数据,并且 api 响应可用。因此,无需打开特定的窗口/对话框,您可以尝试在 POSTMAN 客户端/也在您的代码中传递 api 数据。
添加回答
举报
0/150
提交
取消