Rehama Rehama - 4 years ago 150
Java Question

Jsoup select links for different websites

I am filtering links out of a html body using JSOUP.

for such a webpage:

i want to filter links such as:

for hash tag links

i try"a[href*=#]").remove();
and it works well where hash tag links in page html src:
<a href="#cite_ref-1">

but when i use"a[href]*=/]").remove();
where links in page html src

<a href="/wiki/Light">CH</a>

But there are still links not filtered . How is this possible?

Answer Source

You have a typo."a[href]*=/]").remove();

It should be like this"a[href*=/]").remove();

But this would remove every link containing a /. Is this what you want, or do you want to remove every link that starts with /. In that case you need this"a[href^=/]").remove();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download