Now Place:2uzhan.com » Web Source Parsing

Web Source Parsing

Software Development @ November 8, 2010   Views:0

Hi, firstly my english is not very good so ım sory about that.
ı want to parse a web source. ı got the source code with urlconnection in jTextArea but ı cant get between two html tag
for ex.
<p class="asd">asdasdasdas </p>
<p class="asd2">bdfgfdgdfgf </p>
<p class="AltBaslik">I want to this </p>
<p class="bbb">bbbbbbbb</p>

ı cant get " ı want to this "

how can ı get this string please some help.


Did you get the first two?? (asdasdasdas & bdfg...)

If yes, then how??

Pls post your code here.

Use some XML library to help you with parsing, also some current code would be helpful to find out what you doing and where you going wrong

ı can get only full source. ı cant get any selected two tag

If you want to do parsing manually from text, read it in line-by-line and try to find an index of the matching open and close tag. Of course, this would assume that all tags are done correctly (no invalid nested tags or no open-with-no-close tags).

can you write a little example?

// Assumptions
//   1.Tags in the string are valid (have open & close including no invalid nested)
//   2.There is only 1 open & close tag of an HTML tag in the string.
//   3.The string must not contain '>' if the line does not have a tag
// If the string doesn't follow the assumption, this example won't work!

// create a sample string --> '<p class="asd">asdasdasdas </p>'
String ex1 = "<p class=\"asd\">asdasdasdas </p>";

int idx = ex1.indexOf(">");
String res = "";
if (idx>1) {  // known that '>' cannot be at position 0 or 1
  int nextIdx = ex1.indexOf("<", idx);  // search for '<' starting from idx
  res = ex1.substring(idx+1, nextIdx-1);
// now 'res' contains the substring inside the tag

its working good but cant read jtextarea only read from string variable..

That's the part you need to implement. You need to getText() from your text area and use it as string in the code portion.

Before I get into the specific issues, I want to provide some other details:

  • Normally, I work on a live, paid server (even in dev); I realize that is ...

Yes, WPF. The learning curve is steep, but what amazing things you can do with it!
Look at this hexagon window for instance. Serves no purpose in a business environment ...

Hey there,

I am trying to create a register code. So basicly im making a quiz and every time a user starts up my program he/she needs to register (making ...

© 2018 2uzhan.com Contact