0

How can I get page source of current page?

I make driver.get(link) and I am on main page. Then I use selenium to get other page (by tag and xpath) and when I get good page I'd like to obtain its page source.

I tried driver.page_source() but I obtain page source of main page not this current.

driver = webdriver.Chrome(ccc)
driver.get('https://aaa.com')
check1 = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/button')
check1.click()
time.sleep(1)
check2=driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/div/a')
check2.click()

And after check2.click() I am on page with new link (this link only works by click not directly). How can I get page source for this new link?

I need it to change selenium for Beautiful Soup

wtfvba
  • 25
  • 6

1 Answers1

0

enter image description here

I have used Webdriver and displaying sources of page

Justin Lambert
  • 940
  • 1
  • 7
  • 13
  • Thanks a lot. I edited my question. I had a code in BS but due to changes in website I have to edit it. And I only can get page link which I'm interested in by selenium. And after it I want to back to BS but I need page source of page with proper link (page where I am after check2.click). I can't do this directly using this page link because it is invalid (server error). – wtfvba Jun 20 '20 at 21:29
  • driver = webdriver.Chrome(ccc) driver.get('https://aaa.com') check1 = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/button') check1.click() time.sleep(1) check2=driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[1]/div/a') check2.click(): driver.getPageSource(): (Please don't use absolute Xpath ,use relative Xpath in selenium) – Justin Lambert Jun 21 '20 at 01:14