1
votes

I'm trying to reach some p tags inside blockquote. In this part of the html I'm trying to reach the p tags which have features as;

font face="Verdana, Arial, Helvetica, sans-serif" size="2"

I mean the last 2 p tags with;

font face="Verdana, Arial, Helvetica, sans-serif" size="2"

<blockquote> 
<p>&nbsp;</p>
<p><a href="../index.html"><img src=""align="right" border="0"></a></p>
<p><img src="baslik.gif" width="308" height="80"></p>
<a href="e.html">E</a> <a href="f.html">F</a> <a href="g.html">G</a> 

<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">ABA ALTINDAN 
SİK ÖLÇMEK: (d)-(ar.-türk. f.)-Yetersiz bilgilerle bir erkeğin cinsel gücünü 
tartmaya çalışmak &amp; Az bilgiyle bir şeyin aslını öğrenebileceğini sanmak. 
&quot;O kadar da leyla olunmaz ki canım. Sen kalk aba altından sik ölçmeye 
soyun sonra da o siki görünce bas yaygarayı!&quot;</font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">ABAROT GÖT: (d)-(o.k)-Çalım 
satan, hava atan kişi. &quot;Sen de amma abarot götmüşsün annem, gören de 
sol taşaktan düştün sanır.&quot;</font></p>
<blockquote>

They don't have any id's, tags or etc.

  • How can I reach them?
  • What is the best suitable way to approach this kind of elements?
  • Can i parse the html by its line number for example?
1
is the last line really <blockquote>? It should be </blockquote> I think. - luksch
Yes it is</blockquote>. I just put some part of the web site. The exact source can be forund here;view-source:ikra4.tripod.com/kadinargo/a.html - user5698435
I'm voting to close this question as off-topic because this text includes too many slangs in Turkish. I think user asked this question with bad purpose. User created a new user for asking this question. - fatihyildizhan

1 Answers

1
votes

If you are sure that the elements are always enclosed in the font tags you specified, then you can use these in Jsoup CSS selectors:

String html = ""
            +"<blockquote> "
            +"<p>&nbsp;</p>"
            +"<p><a href=\"../index.html\"><img src=\"\"align=\"right\" border=\"0\"></a></p>"
            +"<p><img src=\"baslik.gif\" width=\"308\" height=\"80\"></p>"
            +"<a href=\"e.html\">E</a> <a href=\"f.html\">F</a> <a href=\"g.html\">G</a> "

            +"<p><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">ABA ALTINDAN "
            +"SİK ÖLÇMEK: (d)-(ar.-türk. f.)-Yetersiz bilgilerle bir erkeğin cinsel gücünü "
            +"tartmaya çalışmak &amp; Az bilgiyle bir şeyin aslını öğrenebileceğini sanmak. "
            +"&quot;O kadar da leyla olunmaz ki canım. Sen kalk aba altından sik ölçmeye "
            +"soyun sonra da o siki görünce bas yaygarayı!&quot;</font></p>"
            +"<p><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">ABAROT GÖT: (d)-(o.k)-Çalım "
            +"satan, hava atan kişi. &quot;Sen de amma abarot götmüşsün annem, gören de "
            +"sol taşaktan düştün sanır.&quot;</font></p>"
            +"</blockquote>";
Document doc = Jsoup.parse(html);
Elements els = doc.select("blockquote p font[face=Verdana, Arial, Helvetica, sans-serif]");
for (Element e : els){
  System.out.println(e.text());
} 

This prints two lines:

ABA ALTINDAN SİK ÖLÇMEK: (d)-(ar.-türk. f.)-Yetersiz bilgilerle bir erkeğin cinsel gücünü tartmaya çalışmak & Az bilgiyle bir şeyin aslını öğrenebileceğini sanmak. "O kadar da leyla olunmaz ki canım. Sen kalk aba altından sik ölçmeye soyun sonra da o siki görünce bas yaygarayı!"
ABAROT GÖT: (d)-(o.k)-Çalım satan, hava atan kişi. "Sen de amma abarot götmüşsün annem, gören de sol taşaktan düştün sanır."

ADDENDUM

I tried now with the URL you provide:

String url = "http://ikra4.tripod.com/kadinargo/a.html";
Document doc= Jsoup.parse(new URL(url).openStream(), "ISO-8859-9", url);

Elements els = doc.select("blockquote p font[face=Verdana, Arial, Helvetica, sans-serif]");
for (Element e : els){
  System.out.println(e.text());
} 

Note that the website does not respond with the correct HTTP header indicating the used encoding. JSoup falls back to the encoding of the system you are running on, which is probably wrong. So you need to use URL.openStream with explicit encoding info to get the page as you want it.