public class HTMLTag extends Object
Constructor and Description |
---|
HTMLTag(String theSourceCode) |
HTMLTag(URL theUrl) |
HTMLTag(URL theUrl,
boolean xmlContent) |
Modifier and Type | Method and Description |
---|---|
static String |
getContentAttribute(String attr,
String tagContent)
Static function that returns the content of an attribute from the text of
a tag.
|
String |
getDataFromTagToTag(String tag1,
String tag2)
Finds and returns the text that contains all the inner data between two
tags.
|
String |
getDataFromTagToTag(String tag1,
String tag2,
int fromIndex)
Finds and returns the text that contains all the inner data between two
tags.
|
String |
getFirstTag()
Finds and returns the name of the first tag (e.g.
|
String |
getFirstTag(int fromIndex)
Finds and returns the name of the first tag (e.g.
|
String |
getFirstTagContent(String theTag)
Finds and returns the text that contains all the attributes of the first
retrieved tag.
|
String |
getFirstTagContent(String theTag,
int fromIndex)
Finds and returns the text that contains all the attributes of the first
retrieved tag.
|
String |
getFirstTagContentContains(String theTag,
String containment)
Finds and returns the text that contains all the attributes of the first
retrieved tag.
|
String |
getFirstTagContentContains(String theTag,
String containment,
int fromIndex)
Finds and returns the text that contains all the attributes of the first
retrieved tag.
|
String |
getFirstTagData(String theTag)
Finds and returns the text that contains all the inner data of the first
retrieved tag.
|
String |
getFirstTagData(String theTag,
int fromIndex)
Finds and returns the text that contains all the inner data of the first
retrieved tag.
|
String |
getFirstTagDataContains(String theTag,
String containment)
Finds and returns the text that contains all the inner data of the first
retrieved tag.
|
String |
getFirstTagDataContains(String theTag,
String containment,
int fromIndex)
Finds and returns the text that contains all the inner data of the first
retrieved tag.
|
String |
getFirstTagDataContentEquals(String theTag,
String containment)
Finds and returns the text that contains all the inner data of the first
retrieved tag.
|
String |
getFirstTagDataContentEquals(String theTag,
String containment,
int fromIndex)
Finds and returns the text that contains all the inner data of the first
retrieved tag.
|
int |
getFirstTagIndex(String theTag)
Finds and returns the position of the first occurrence of a tag.
|
int |
getFirstTagIndex(String theTag,
int fromIndex)
Finds and returns the position of the first occurrence of a tag.
|
int |
getFirstTagIndexContains(String theTag,
String containment)
Finds and returns the position of the first occurrence of a tag that
contains a particular text in its attributes' text.
|
int |
getFirstTagIndexContains(String theTag,
String containment,
int fromIndex)
Finds and returns the position of the first occurrence of a tag that
contains a particular text in its attributes' text.
|
int |
getFirstTagIndexContentEquals(String theTag,
String containment)
Finds and returns the position of the first occurrence of a tag that its
attributes' text is equal to a particular text.
|
int |
getFirstTagIndexContentEquals(String theTag,
String containment,
int fromIndex)
Finds and returns the position of the first occurrence of a tag that its
attributes' text is equal to a particular text.
|
static String |
getHref(String tagA)
Static function that returns the content of the 'href' attribute from the
text of an 'a' tag.
|
int |
getNumOfTags(String theTag)
Finds the number of occurrences of a tag.
|
int |
getNumOfTags(String theTag,
int fromIndex)
Finds the number of occurrences of a tag.
|
int |
getNumOfTags(String theTag,
int fromIndex,
int toIndex)
Finds the number of occurrences of a tag.
|
String |
getSourceCode() |
URL |
getUrl() |
boolean |
isError() |
static String |
readFile(String filepath)
Static function that reads a file path and returns the contents of the
file.
|
static String |
removeTag(String tag,
String text)
Static function that removes all occurrences of a particular tag (and its
inner data) from a text.
|
static String |
removeTagButNoText(String tag,
String text)
Static function that removes all occurrences of a particular tag (without
its inner data) from a text.
|
static String |
removeTags(String text)
Static function that removes all the tags (without their inner data) from
a text.
|
static String |
removeTagsNoTagB(String text)
Static function that removes all the tags (without their inner data) from
a text, apart from "b" tags.
|
void |
setError(boolean error) |
public HTMLTag(URL theUrl)
theUrl
- The URL of the page that you want to analyze.public HTMLTag(URL theUrl, boolean xmlContent)
theUrl
- The URL of the page that you want to analyze.xmlContent
- True if the URL of the page that you want to analyze is
an XML page.public HTMLTag(String theSourceCode)
theSourceCode
- A string that you want to analyze.public String getFirstTag()
public String getFirstTag(int fromIndex)
fromIndex
- Start searching from that position (value must be
between 0 and contents' total length)public int getFirstTagIndex(String theTag)
theTag
- The name of the tag (e.g. "div")public int getFirstTagIndex(String theTag, int fromIndex)
theTag
- The name of the tag (e.g. "div")fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public int getFirstTagIndexContains(String theTag, String containment)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag to contain in its
attributes' text.public int getFirstTagIndexContains(String theTag, String containment, int fromIndex)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag to contain in its
attributes' text.fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public int getFirstTagIndexContentEquals(String theTag, String containment)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag's attributes text to be
equal to.public int getFirstTagIndexContentEquals(String theTag, String containment, int fromIndex)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag's attributes text to be
equal to.fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public String getFirstTagContent(String theTag)
theTag
- The name of the tag (e.g. "a")public String getFirstTagContent(String theTag, int fromIndex)
theTag
- The name of the tag (e.g. "a")fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public String getFirstTagContentContains(String theTag, String containment)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag to contain in its
attributes' text.public String getFirstTagContentContains(String theTag, String containment, int fromIndex)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag to contain in its
attributes' text.fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public String getFirstTagData(String theTag)
theTag
- The name of the tag (e.g. "div")public String getFirstTagData(String theTag, int fromIndex)
theTag
- The name of the tag (e.g. "div")fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public String getFirstTagDataContains(String theTag, String containment)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag to contain in its
attributes' text.public String getFirstTagDataContains(String theTag, String containment, int fromIndex)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag to contain in its
attributes' text.fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public String getFirstTagDataContentEquals(String theTag, String containment)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag's attributes text to be
equal to.public String getFirstTagDataContentEquals(String theTag, String containment, int fromIndex)
theTag
- The name of the tag (e.g. "div")containment
- The text that you want the tag's attributes text to be
equal to.fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public int getNumOfTags(String theTag)
theTag
- The name of the tag (e.g. "div")public int getNumOfTags(String theTag, int fromIndex)
theTag
- The name of the tag (e.g. "div")fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public int getNumOfTags(String theTag, int fromIndex, int toIndex)
theTag
- The name of the tag (e.g. "div")fromIndex
- Start searching from that position (value must be
between 0 and content's total length)toIndex
- End searching at that position (value must be between @start
and content's total length)public String getDataFromTagToTag(String tag1, String tag2)
tag1
- tag1 The name of the first tag (e.g. "div")tag2
- The name of the last tag (e.g. "div")public String getDataFromTagToTag(String tag1, String tag2, int fromIndex)
tag1
- The name of the first tag (e.g. "div")tag2
- The name of the last tag (e.g. "div")fromIndex
- Start searching from that position (value must be
between 0 and content's total length)public static String removeTags(String text)
text
- The text from which you want to remove all tags.public static String removeTagButNoText(String tag, String text)
tag
- The name of the tag (e.g. "div")text
- The text from which you want to remove the particular tag.public static String removeTag(String tag, String text)
tag
- The name of the tag (e.g. "div")text
- The text from which you want to remove the particular tag.public static String removeTagsNoTagB(String text)
text
- The text from which you want to remove all tags apart from
"b" tags.public static String getHref(String tagA)
public static String getContentAttribute(String attr, String tagContent)
attr
- The attribute from which you want to get the content.tagContent
- The text of the tag from which you want to get the
content of the attribute @attr.public static String readFile(String filepath) throws FileNotFoundException, UnsupportedEncodingException, IOException
filepath
- The path of the file you want to read.FileNotFoundException
UnsupportedEncodingException
IOException
public URL getUrl()
public String getSourceCode()
public boolean isError()
public void setError(boolean error)
error
- True if an error has occurred to the current HTMLTag object.Copyright © 2014. All rights reserved.