I want to parse a HTML file in Java which has JavaScript also in it. I want to fetch the data of Java Script tag also. The tag is SCRIPT. Please help with suggestions / solutions.
I have tried using Java HTMLEditorKit API but it does not work for SCRIPT tag/
Regards,
Sagar
4 1813 JosAH 11,448
Recognized Expert MVP
I want to parse a HTML file in Java which has JavaScript also in it. I want to fetch the data of Java Script tag also. The tag is SCRIPT. Please help with suggestions / solutions.
I have tried using Java HTMLEditorKit API but it does not work for SCRIPT tag/
Regards,
Sagar
I haven't tried it but define an HTML.UnknownTag with the "SCRIPT" as the
identifier. Then try to get an HTMLDocument.It erator from the HTMLDocument
given this tag. Given this iterator you should be able to get the text between tags
of the SCRIPT type.
kind regards,
Jos
You can use Jericho HTML Parser.
http://jerichohtml.sou rceforge.net/doc/index.html
The author says that the ASP, JSP, PSP, PHP and Mason server tags are explicitly recognised by the parser
I have tried using it Jos but it does not works.
<SCRIPT> document.write ( "<A onclick=\"OpenM SDigestWin()\" target=\"MSDige stWin\" HREF = \"" + msdigestLink + "dna_reading_fr ame=1&access_me thod=Accession+ Number&hide_pro tein_sequence=2 &open_reading_f rame=1&coverage _map=0+138+13+3 2+14+38+6+25+14 +5+12+77+12+ 34+13+4+14+97+9 +23+27&search_c ycle=1&accessio n_num=P02769\"> 22%</A>" );</SCRIPT>
I want to parse this code and want the text between anchor tag which I have made bold. I am trying using HTMLEditorKit.P arserCallback but it does not works for above piece of code.
Please help me with the solution / suggestions.
regards,
I have build my own methowd which parse the SCRIPT Tag. Using HTMLEditorKit.P arserCallback, I diverted the control flow whenever a SCRIPT tag occured.
This method would have handle any <SCRIPT> tag in a HTML file. Also< i wanted the <A> which is placed in SCRIPT tag which i am also able to get. thanks for every1 who contributed to my queriers.
Below is the code.
BufferedReader br;
boolean checkLineForScr ipt = false;
String tempGlobalStrin g = "";
String parsedScriptTag = "", tempString = "", fullScriptTag = "",
scriptStart = "", scriptEnd = "", str = "", actualDataToken = "";
int getScriptTagSta rtPosition = 0 , getScripttagEnd Position = -1,
tempPosition = -1, lastindex = 0, anchorTagEndPos ition = -1,
anchorTagStartP osition = -1;
try
{
if(checkLineFor Script == true)
{
getScriptTagSta rtPosition = tempGlobalStrin g.indexOf("<SCR IPT");
lastindex = tempGlobalStrin g.length();
getScripttagEnd Position = tempGlobalStrin g.indexOf("</SCRIPT>");
if(getScriptTag StartPosition > getScripttagEnd Position)
{
fullScriptTag = tempGlobalStrin g.substring(get ScriptTagStartP osition, lastindex);
in: while((scriptEn d = br.readLine()) != null)
{
getScripttagEnd Position = scriptEnd.index Of("</SCRIPT>");
if(getScripttag EndPosition == -1)
{
fullScriptTag = fullScriptTag + scriptEnd;
continue in;
}
else
{
tempString = scriptEnd.subst ring(0,getScrip ttagEndPosition );
fullScriptTag = tempString + fullScriptTag;
anchorTagEndPos ition = fullScriptTag.i ndexOf("</A>");
if(anchorTagEnd Position > -1)
{
anchorTagStartP osition = fullScriptTag.i ndexOf("\">");
actualDataToken = fullScriptTag.s ubstring(anchor TagStartPositio n+2,
anchorTagEndPos ition);
//System.out.prin tln(actualDataT oken);
}
System.out.prin tln(fullScriptT ag);
break in;
}
}
}
else if(getScriptTag StartPosition < getScripttagEnd Position)
{
parsedScriptTag = tempGlobalStrin g.substring(get ScriptTagStartP osition, getScripttagEnd Position);
anchorTagEndPos ition = parsedScriptTag .indexOf("</A>");
if(anchorTagEnd Position > -1)
{
anchorTagStartP osition = parsedScriptTag .indexOf("\">") ;
actualDataToken = parsedScriptTag .substring(anch orTagStartPosit ion+2,
anchorTagEndPos ition);
//System.out.prin tln(actualDataT oken);
}
System.out.prin tln(parsedScrip tTag);
}
}
else
{
out: while ((scriptStart = br.readLine()) != null)
{
getScriptTagSta rtPosition = scriptStart.ind exOf("<SCRIPT") ;
lastindex = scriptStart.len gth();
getScripttagEnd Position = scriptStart.ind exOf("</SCRIPT>");
if(getScriptTag StartPosition > getScripttagEnd Position)
{
fullScriptTag = scriptStart.sub string(getScrip tTagStartPositi on, lastindex);
in: while((scriptSt art = br.readLine()) != null)
{
getScripttagEnd Position = scriptStart.ind exOf("</SCRIPT>");
if(getScripttag EndPosition == -1)
{
fullScriptTag = fullScriptTag + scriptStart;
continue in;
}
else
{
tempString = scriptStart.sub string(0,getScr ipttagEndPositi on);
fullScriptTag = tempString + fullScriptTag;
anchorTagEndPos ition = fullScriptTag.i ndexOf("</A>");
if(anchorTagEnd Position > -1)
{
anchorTagStartP osition = fullScriptTag.i ndexOf("\">");
actualDataToken = fullScriptTag.s ubstring(anchor TagStartPositio n+2,
anchorTagEndPos ition);
//System.out.prin tln(actualDataT oken);
}
//System.out.prin tln(fullScriptT ag);
break out;
}
}
}
else if(getScriptTag StartPosition < getScripttagEnd Position)
{
parsedScriptTag = scriptStart.sub string(getScrip tTagStartPositi on, getScripttagEnd Position);
anchorTagEndPos ition = parsedScriptTag .indexOf("</A>");
if(anchorTagEnd Position > -1)
{
anchorTagStartP osition = parsedScriptTag .indexOf("\">") ;
actualDataToken = parsedScriptTag .substring(anch orTagStartPosit ion+2
, anchorTagEndPos ition);
//System.out.prin tln(actualDataT oken);
}
//System.out.prin tln(parsedScrip tTag);
break out;
}
}
lastindex = scriptStart.len gth();
str = scriptStart.sub string(getScrip ttagEndPosition , lastindex);
tempPosition = str.indexOf("<S CRIPT");
lastindex = str.length();
}
if(tempPosition > 0)
{
checkLineForScr ipt = true;
tempGlobalStrin g = str.substring(t empPosition, lastindex);
}
else
checkLineForScr ipt = false;
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Terry |
last post by:
Hi,
This is a newbie's question. I want to preload 4 images and only when
all 4 images has been loaded into browser's cache, I want to start a
slideshow() function. If images are not completed loaded into cache,
the slideshow doesn't look very nice.
I am not sure how/when to call the slideshow() function to make sure it
starts after the preload has been completed.
|
by: Sven Neuberg |
last post by:
Hi,
I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all concatenated into monstrously long strings
of text that are then submited as <hidden> inputs in HTML forms...
|
by: Esa |
last post by:
Hi,
I'm having problems with one strange web system where submitting an
application and making queries about its handling status require a series of
form submits and response parsing - all in HTML. Luckily other interfaces
are "modern" using xml file up/downloads without any difficulties...
I'm not very used to .NET-environment yet, so I'd appreciate some clues
about the classes I should use to implement this stupid interface - stupid...
|
by: Martin Walke |
last post by:
Hi all,
Can someone help me out here? I'm been using ASP and VBScript for some years
but have just ventured into the realms of using server side Javascript and
apart from hitting various niggerly problems, this one baffles me.
This is a very simplistic example of the problem.
<%@ Language="JavaScript"%>
|
by: Rick Walsh |
last post by:
I have an HTML table in the following format:
<table>
<tr><td>Header 1</td><td>Header 2</td></tr>
<tr><td>1</td><td>2</td></tr>
<tr><td>3</td><td>4</td></tr>
<tr><td>5</td><td>6</td></tr>
</table>
With an XSLT styles sheet, I can use for-each to grab the values in
| |
by: bruce |
last post by:
hi...
it appears that i'm running into a possible problem with
mechanize/browser/python rgarding the "select_form" method. i've tried the
following and get the error listed:
br.select_form(nr = 1)
br.select_form(name="foo")
br.select_form(name=foo)
br.select_form(name="foo")
|
by: Rodrigo Meza |
last post by:
Hello Everyone
For a project I am working on, I need to retrieve links from html
documents. The easy part is to obtain 'plain' links like <A
HREF="http://site/path/document">, but when those links are
javascript'ized, the only robust solution needs to load the javascript
and dom document representation in the same way that browsers do. For
example, links in the form:
<A HREF="javascript:function_declared_before("arguments"));>
|
by: hzgt9b |
last post by:
I've written a simple javascript page that parses an XML file...
(Actually I just modified the "Parsing an XML File" sample from
http://www.w3schools.com/dom/dom_parser.asp)
The page works great standalone... but when I try to make this work
under frames I get "Error: Object required" when the following line
executes:
xmlDoc.getElementsByTagName("to");
The standalone file is named treeView.htm (attached). You should be
|
by: avpkills2002 |
last post by:
I seem to be getting this weird problem in Internet explorer. I have
written a code for parsing a XML file and displaying the output. The
code works perfectly fine with ffx(Firefox).However is not working in
Internet Explorer.(I m using Internet Explorer 6.0). The code is as
follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html...
|
by: Philip Semanchuk |
last post by:
On Oct 12, 2008, at 5:25 AM, S.Selvam Siva wrote:
Selvam,
You can try to find them yourself using string parsing, but that's
difficult. The closer you want to get to "perfect" at finding URLs
expressed in JS, the closer you'll get to rewriting a JS interpreter.
For instance, this is not so hard to understand:
"http://example.com/"
but this is:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |