Closed gangadharkasturi closed 1 year ago
@gangadharkasturi
Have done some small changes
Finally the code below produces:
TATA 1MG HEALTHCARE SOLUTIONS PRIVATE LIMITED - U24290DL2016PTC302634 - Delhi - Active - -
TATA 1MG TECHNOLOGIES PRIVATE LIMITED - U74140DL2015PTC279229 - Delhi - Active - -
TATA ADVANCED MATERIALS LIMITED - U85110KA1989PLC013224 - Karnataka - Amalgamated - -
TATA ADVANCED SYSTEMS LIMITED - U72900TG2006PLC077939 - Telangana - Active - -
TATA AIA LIFE INSURANCE COMPANY LIMITED - U66010MH2000PLC128403 - Maharashtra - Active - -
TATA AIG GENERAL INSURANCE COMPANY LIMITED - U85110MH2000PLC128425 - Maharashtra - Active - -
TATA ALUMINIUM LIMITED - U14200DL1991PLC042748 - Delhi - Strike Off - -
TATA ASSET MANAGEMENT PRIVATE LIMITED - U65990MH1994PTC077090 - Maharashtra - Active - -
TATAATSU IDEALABS PRIVATE LIMITED - U72900KA2011PTC060663 - Karnataka - Active - -
TATA AUTOCOMP GOTION GREEN ENERGY SOLUTIONS PRIVATE LIMITED - U29304PN2020PTC190510 - Maharashtra - Active - -
My code:
public class Test {
private static final String url = "https://www.mca.gov.in/content/mca/global/en/mca/master-data/MDS.html";
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX)) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
new InterceptWebConnection(webClient);
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScriptStartingBefore(10_000);
HtmlTextInput elementById = (HtmlTextInput) page.getElementById("masterdata-search-box");
elementById.type("TATA");
webClient.waitForBackgroundJavaScriptStartingBefore(2_000);
HtmlTable table = (HtmlTable) page
.getByXPath("//*[@id=\"fohomepage-037f88dfd8\"]/div/div/div[3]/div/div[1]/div[1]/div/div[2]/table")
.get(0);
StringBuffer str = new StringBuffer();
HtmlTableBody htmlTableBody = table.getBodies().get(0);
for (final HtmlTableRow row : htmlTableBody.getRows()) {
for (final HtmlTableCell cell : row.getCells()) {
str.append(cell.asNormalizedText()).append(" - ");
}
str.append("\n");
}
System.out.println(str);
}
}
private static final class InterceptWebConnection extends FalsifyingWebConnection {
public InterceptWebConnection(WebClient webClient) throws IllegalArgumentException {
super(webClient);
}
@Override
public WebResponse getResponse(WebRequest request) throws IOException {
WebResponse response = super.getResponse(request);
String respUrl = response.getWebRequest().getUrl().toString();
if (respUrl.endsWith("disable-devtool") || respUrl.endsWith("clientlib-site.min.js")) {
return createWebResponse(response.getWebRequest(), "", "application/javascript", 200, "Ok");
}
return super.getResponse(request);
}
}
}
Hope that helps
It works, Thanks for the help.
Great (github stars are always welcome - and if you use HtmlUnit for business purposes you can also think about sponsoring)
HTMLUnit not calling the JQuery on key release events.
Sample Code:
Support class;
We are supposed to receive the suggestion but that is not happening