Issue
I need to get the source code of the page after changing it, I send a request to the page, then the page opens in my browser, I select some data with my hands, and after that, a table appears with the necessary data, how after all these operations can I take this table or get full page code after changes
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
links=['https://priem.gubkin.ru/#/page/enrollment']
s=Service(executable_path='D:\\university\\geckodriver.exe')
driver = webdriver.Firefox(service=s)
try:
driver.maximize_window()
for i in range(0,len(links)):
driver.get(links[i])
# time.sleep(25)
element = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "tbody")))
with open('GUBKINA.html', 'w') as file:
file.write(element)
except Exception as ex:
print(ex)
finally:
driver.close()
driver.quit()
I tried to get this table with the help of waits and finding a class of this table, but a program can't find this element and write that nosuchelenterror and etc
Solution
I think your problem is that the links that you want are in an iFrame. Try something like this:
iframe = driver.find_element(By.XPATH, "//iframe") #find the iframe
driver.switch_to.frame(iframe) # go into it
items = driver.find_elements(By.XPATH, "//span") # do stuff
for item in items:
print(unidecode(item.text))
driver.switch_to.default_content() # exit the iframe
I couldn't find any elements with the class of "tbody", but the CSS for that is on the site. The code above prints the following in unicode:
Spisok abiturientov
Forma obucheniia
Forma obucheniia
Forma obucheniia
Answered By - Ned Hulton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.