[英]Dealing with WebForm_DoPostBackWithOptions When scraping a website
I'm attempting to scrape an aspx website showing a list of search results using selenium; 我正在尝试使用selenium来搜索显示搜索结果列表的aspx网站; when the script 'clicks' a button an alert pops up - I tried 'clicking' the alert-button to continue to the next page using
EC.alert_is_present
but it raised an ValueError: No JSON object could be decoded
error. 当脚本“点击”按钮时会弹出一个警告 - 我尝试'点击'警告按钮继续使用
EC.alert_is_present
到下一页,但它引发了一个ValueError: No JSON object could be decoded
错误。
Looking at the code of the button itself using 'inspect element shows: 使用'inspect element shows查看按钮本身的代码:
<a onclick="WaitPlease('_ctl0_btnDownloadWordDocs');
if (ConfirmWordDocDownload()==false) return false;"
id="_ctl0_btnDownloadWordDocs" class="ButtonsMedium" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("_ctl0:btnDownloadWordDocs", "", true, "", "",false, true)) onclicksaved="function onclick(event){ WaitPlease('_ctl0_btnDownloadWordDocs');
if(ConfirmWordDocDownload()==false) return false;}">...</a>
My guess it has something to do with the WebForm_DoPostBackWithOptions
right after the href
but googling didn't get me any reference to this situation. 我的猜测它与
href
之后的WebForm_DoPostBackWithOptions
有关,但谷歌搜索没有让我对这种情况有任何参考。
Thanks. 谢谢。
I did have the same error. 我确实有同样的错误。 But with jQuery o javascript is not necessary to execute from selenium the onClick content, just use jQuery or javascript -> to make click in the element.
但是使用jQuery o javascript不需要从selenium执行onClick内容,只需使用jQuery或javascript - >来点击元素。
String onClick = "$('#_ctl0_btnDownloadWordDocs').click();";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeAsyncScript(onClick);
Some update about time out. 一些关于超时的更新。
try {
driver.manage().timeouts().setScriptTimeout(500,TimeUnit.MILLISECONDS);
String onClick = "$('#MainContent_btnConsultar').click();";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeAsyncScript(onClick);
} catch (ScriptTimeoutException e) {
e.printStackTrace();
}
I hope this resolve your error as mine. 我希望这能解决你的错误。 Maybe you must to update from Java to Python
也许你必须从Java更新到Python
Imports you need 您需要的进口
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.ScriptTimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.