简体   繁体   中英

Python Get on a website and running $(document).ready(function()

I am doing some testing on my site, and I have a python program which does gets on few different pages. Some of these pages have $(document).ready(function() . I noticed that when I do get through python, I get the code, but for example $(document).ready(function() doesn't run.

How can I run the $(document).ready(function() of the site I am doing a GET on?

Thank you for help.

You should go for Selenium , it lets you control a real browser from your python code . That means your javascript will be executed by the browser .

Example code :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM