我想下载由代码生成的网页Javascript并将其存储到字符串变量中Python。当您单击按钮时会生成该页面。
如果我知道我会使用的结果 URL,urllib2但事实并非如此。
谢谢
我想下载由代码生成的网页Javascript并将其存储到字符串变量中Python。当您单击按钮时会生成该页面。
如果我知道我会使用的结果 URL,urllib2但事实并非如此。
谢谢
您可以使用Selenium Webdriver:
#!/usr/bin/env python
from contextlib import closing
from selenium.webdriver import Firefox # pip install selenium
from selenium.webdriver.support.ui import WebDriverWait
# use firefox to get page with javascript generated content
with closing(Firefox()) as browser:
     browser.get(url)
     button = browser.find_element_by_name('button')
     button.click()
     # wait for the page to load
     WebDriverWait(browser, timeout=10).until(
         lambda x: x.find_element_by_id('someId_that_must_be_on_new_page'))
     # store it to string variable
     page_source = browser.page_source
print(page_source)