R
rh1200la
Hey all. I'm doing a very basic screen scrape of a page that displays
a banner ad. It is basically an <A> tag and an <IMG> tag. I need to
grab the url of each and store them.
Right now I can download the page fine into my code but I'm having a
problem on this line:
imgTag = m_strSite.Substring(imageStart, imageEnd);
I get the following error:
Index and length must refer to a location within the string. Parameter
name: length
the strange thing is when I use Substring and use a start value greater
than 5 I get the error.
Here is my code:
private string m_strSite;
private void Page_Load(object sender, System.EventArgs e)
{
string currURL = "http://someurl.com?vars";
m_strSite = OpenSite(currURL);
int imageStart;
int linkStart = 0;
int linkEnd;
int imageEnd = m_strSite.Length - 6 ;
string urlTag;
string imgTag;
imageStart = Find("<img", 0);
linkEnd = imageStart;
urlTag = m_strSite.Substring(linkStart, linkEnd);
imgTag = m_strSite.Substring(imageStart, imageEnd);
}
private int Find(string strSearch, int nStart)
{
return m_strSite.IndexOf(strSearch, nStart);
}
a banner ad. It is basically an <A> tag and an <IMG> tag. I need to
grab the url of each and store them.
Right now I can download the page fine into my code but I'm having a
problem on this line:
imgTag = m_strSite.Substring(imageStart, imageEnd);
I get the following error:
Index and length must refer to a location within the string. Parameter
name: length
the strange thing is when I use Substring and use a start value greater
than 5 I get the error.
Here is my code:
private string m_strSite;
private void Page_Load(object sender, System.EventArgs e)
{
string currURL = "http://someurl.com?vars";
m_strSite = OpenSite(currURL);
int imageStart;
int linkStart = 0;
int linkEnd;
int imageEnd = m_strSite.Length - 6 ;
string urlTag;
string imgTag;
imageStart = Find("<img", 0);
linkEnd = imageStart;
urlTag = m_strSite.Substring(linkStart, linkEnd);
imgTag = m_strSite.Substring(imageStart, imageEnd);
}
private int Find(string strSearch, int nStart)
{
return m_strSite.IndexOf(strSearch, nStart);
}