在Python-Selenium中调用Javascript函数

在Python-Selenium中调用Javascript函数,python,selenium-webdriver,Python,Selenium Webdriver,我用python脚本处理/废弃了以下HTML代码: <a href="javascript:VerMapa('AVDA. DE AMERICA, 2 -33880 POLA DE ALLANDE','RODRIGUEZ-PELAEZ PEÑA, ANA MARIA','AVDA. DE AMERICA, 2 -33880','33880','ALLANDE','183','178')"><img src="../../Fijos/Img/VerMapa.jpg" alt="

我用python脚本处理/废弃了以下HTML代码:

<a href="javascript:VerMapa('AVDA. DE AMERICA, 2  -33880 POLA DE ALLANDE','RODRIGUEZ-PELAEZ PEÑA, ANA MARIA','AVDA. DE AMERICA, 2  -33880','33880','ALLANDE','183','178')"><img src="../../Fijos/Img/VerMapa.jpg" alt="" width="25" height="24" border="0">&nbsp;<br>Ver Mapa</a>
我要给VerMapa'AVDA打个电话。美国,2-33880 POLA DE ALLANDE',“罗德里格斯-佩雷兹佩尼亚,安娜·玛丽亚”,阿夫达。DE AMERICA,href属性中的2-33880'、'33880'、'ALLANDE'、'183'、'178'javascript函数,并获取返回的HTML代码

我检查过蜘蛛猴和PyV8,但我想他们在这里帮不了我。spider monkey清楚地告诉您不能调用javascript定义的函数

我现在正在尝试使用Selenium,但我不知道如何将源代码恢复到python

据我所知,我刚刚实现了一个测试脚本,并设法在浏览器窗口中加载请求的页面

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.farmasturias.org/GESCOF/cms/Guardias/FarmaciaBuscar.asp?IdMenu=111")
htmlCode = browser.execute_script("return VerMapa('AVDA. DE AMERICA, 2  -33880 POLA DE ALLANDE','RODRIGUEZ-PELAEZ PEÑA, ANA MARIA','AVDA. DE AMERICA, 2  -33880','33880','ALLANDE','183','178')")
print htmlCode;
1.-我在htmlCode变量中没有得到任何东西?我如何才能取回javascript函数生成的源代码?我从这篇文章中获取了语法

2.-有没有办法在不打开任何浏览器窗口的情况下使用Selenium?

VerMapa函数没有返回值。这就是为什么htmlCode变量没有显示任何内容

要获取新窗口的源代码,首先调用VerMapa,然后切换到新窗口,然后获取源代码

# get all open windows
handles = set(broswer.window_handles)

# remove the current window from the set
handles.remove(browser.current_window_handle)

# switch to the other window
browser.switch_to_window(handles.pop())

# get the source of that window
htmlCode = browser.page_source

我用java尝试了相同的代码,并填充了一个新的弹出窗口。在执行javascript并使用print htmlCode之后,您是否需要显示地图的弹出窗口的html源代码?也许我不太清楚。代码弹出一个包含预期内容的新窗口,但htmlCode var中没有返回任何内容。我正在尝试在该var中获取页面的源代码。@DavidCasillas您想要主页的源代码还是新打开的弹出窗口?为弹出窗口创建的on。
# get all open windows
handles = set(broswer.window_handles)

# remove the current window from the set
handles.remove(browser.current_window_handle)

# switch to the other window
browser.switch_to_window(handles.pop())

# get the source of that window
htmlCode = browser.page_source