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

3
  • use this to resolve this stackoverflow.com/questions/8498779/… getPageSource() is method Commented Jun 20, 2020 at 15:13
  • @JustinLambert getPageSource() can't help becasue I use WebDriver Commented Jun 20, 2020 at 15:28
  • yes you can via Webdriver check attachment Commented Jun 20, 2020 at 15:45

1 Answer 1

0

enter image description here

I have used Webdriver and displaying sources of page

Sign up to request clarification or add additional context in comments.

2 Comments

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).
driver = webdriver.Chrome(ccc) driver.get('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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.