2015-06-25 58 views
0

我正在尝试使用Python从此页面获取动态生成的表格(http://xbrl.cninfo.com.cn/XBRL/allinfo.jsp?stkid=000410&getyear=2012&nowpage=Info.jsp&reportType=GB0110)。我已经尝试使用机械化,硒与PhantomJS webdriver模块,但无济于事。以下是我使用的代码的一部分:网页抓取:使用Python获取从JSP生成的HTML源代码

url = 'http://xbrl.cninfo.com.cn/XBRL/allinfo.jsp?stkid=000410&getyear=2012&nowpage=Info.jsp&reportType=GB0110' 
driver = webdriver.PhantomJS() 
driver.set_window_size(1024, 768) 
driver.get(url) 
content = driver.page_source 
# Used BeautifulSoup after this to get all the table content within the iframe tag but it's source is some jsp page. 

我是新来的网页抓取,所以不知道如何刮动态创建的内容。请帮忙。谢谢。

回答

1

这是因为你想要的数据放在iframe中。 试试这个

driver.get(url) 
driver.switch_to.frame(driver.find_element_by_xpath("//iframe")) 
content = driver.page_source 
+0

非常感谢! –