Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

how to find and get some part of text file

hi, i have an object webbrowser that navigate to one specific url and i want after it loads the url then find the image path that is inside this img tab. so i want to return only the path of the image.

        WebBrowser1.ScriptErrorsSuppressed = True
        WebBrowser1.Navigate("myurl")
        ~~ find and return this value: admin/imagens/bs2314_g.jpg


on the html it will be like this:

<img  class="img_produto" src="admin/imagens/bs2314_g.jpg" />
0
rafaelrgl
Asked:
rafaelrgl
  • 3
  • 2
  • 2
  • +1
1 Solution
 
Mohit VijayCommented:
If the image is on server then you get do GetFiles a method from file class and if required you can provide filter also there like *.img etc..
0
 
anarki_jimbelCommented:
If you do not bother to parse HTML and definitely have 1 image only - you may use simple string processing. Just get document text from the browser and do something like:

            string browserText = "<HTML><img  class=\"img_produto\" src=\"admin/imagens/bs2314_g.jpg\" /></HTML>";
            // find image element
            int imgEleIndex = browserText.IndexOf("<img ");
            //Start searching source
            int srcEleIndex = browserText.IndexOf("src=", imgEleIndex);
            // find closing quote
            int closingQuoteIndex = browserText.IndexOf("\"", srcEleIndex+5);
            // result:
            string pathStr = browserText.Substring(srcEleIndex + 5, closingQuoteIndex - srcEleIndex-5 );
            MessageBox.Show(pathStr);

Open in new window

0
 
rafaelrglAuthor Commented:
What i want to do is mine some data from the page, I have this webbrowse1 Object that opens the page and i want to get the imageurl, and some titles, but i can~t find how to read and retrieve those informations. here is the html code of the page i am reading.
<!DOCTYPE html PUBLIC #-//W3C//DTD XHTML 1.0 Transitional//EN#
#http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd#>

<html xmlns=#http://www.w3.org/1999/xhtml# xml:lang=#pt# lang=#pt#>

<head>

<link href=#css/estilos.css# type=#text/css# rel=#stylesheet# />
<meta http-equiv=#Content-Type# content=#text/html; charset=windows-1252# />
	
<script language=#javascript#>
var url = window.opener.location.href;

  function comprar(codigo, qtde, opcoes)
  {
    if (window.opener != null)
    {
      if (url == window.opener.location.href)
      {
        window.opener.focus();
        window.opener.inserir_item(codigo, qtde, opcoes, );
        setTimeout('window.close()', 10000);
      }
      else
      {
        alert('N¿o ¿ poss¿vel adicionar o item em sua cesta de compras, pois o endere¿o da janela principal da Imagem Folheados foi alterado.');
      }
    }
    else
    {
      alert('N¿o ¿ poss¿vel adicionar o item em sua cesta de compras, pois a janela principal da Imagem Folheados foi fechada.');
      window.close();   
    }
  }
  
  function getOption(select)
  {
    if (select != null)
    {
      return select.value;
    }
    else
      return ##;
  }
</script>



<title>Imagem Folheados - Detalhes do produto</title>
</head>

<body>

<div id=#fundo2#>
	<div id=#geral2#>

			<div id=#conteudo2#>
				<div class=#fundo_cat_sup#>
					<h2>Detalhes do Produto BS2314</h2>
				</div>

				<div id=#detalhes_prod# class=#fundo_cat_meio#>
					<div class=#produto#>
						<h3>C¿digo: BS2314<img alt='NOVO!!!' border='0' src='imagens/novo.gif'></h3>
						<div class=#foto_produto#>
							<img class=#img_novo# border=#0# src=#imagens/novo_etiqueta.gif#>
							<img  class=#img_produto# src=#admin/imagens/bs2314_g.jpg# />	
							          <div class=#div_aviso#>
          <p class=#destaque#><b>ATEN¿¿O:</b><p> <p>Foto ampliada. Veja as dimens¿es mais abaixo.</p>
          </div>	
							
						</div>
						<div class=#dados_produto#>
							<p>red car.</p>
							<div class=#space#></div>
							<p>Pre¿o Atacado: <span class='preco_normal'>R$ 12,85</span>&nbsp;&nbsp;(unid.: par)<br />
								Pre¿o Varejo: <span class='preco_normal'>R$ 25,70</span>&nbsp;&nbsp;(unid.: par)<br />
								Garantia: <span class=#destaque2#>1 ano ap¿s a data da compra</span><br />
								Prazo de Libera¿¿o: <span class=#destaque#>At¿ 48 horas</span> (somente dias ¿teis)
							</p>
								<div class='space'></div><p><strong>Dimens¿es Aproximadas:</strong><br />-comprimento: 1,5 cm<br>-largura: 1,8 cm</p>
							<form id=#form# name=#form#>
								<fieldset>
									<input type=#hidden# name=#direcionar# value=#detalhes_prod2.asp# />
									<input type=#hidden# name=#id# value=#4640# />
									<input type=#hidden# name=#ancora# value=## />
									<input type=#hidden# name=#inserir# value=#sim# />
									<input type=#hidden# name=#detalhes# value=#sim# />
									</p>
									<p>Quantidade na cesta: <span class=#destaque2#><b>--</b></span><br />
									
										<select size=#1# name=#Quantidade#>
											<option selected value=#1#>1</option>
											<option value=#2#>2</option>
											<option value=#3#>3</option>
											<option value=#4#>4</option>
											<option value=#5#>5</option>
											<option value=#6#>6</option>
											<option value=#7#>7</option>
											<option value=#8#>8</option>
											<option value=#9#>9</option>
											<option value=#10#>10</option>
										</select> 
										<img onclick=#comprar(4640, document.form.Quantidade.value, getOption(document.form.Opcoes))# class=#bt_compre# scr=#imagens/bt_compre.gif# border=#0# src=#imagens/bt_compre.gif# alt=#Clique para comprar# width=#75# height=#25# />
																		
								</fieldset>
							</div>
						</form>
					</div>
					<p class=#centro#><input type=#button# value=#Fechar Janela# name=#B3# class=#Button# onclick=#window.close()# /></p>
				</div>
				<div class=#fundo_cat_inf#>
				</div>

<div class='space'></div>
			</div>
			
	</div>
</div>


</body>
	

</html>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
anarki_jimbelCommented:
OK, the document is complex enough and I do not think simple string handling is suitable.
I think you need HTML parsing and looking for proper elements. You can do the search yourself, check something like ".net c# html parsing".
0
 
CodeCruiserCommented:
0
 
rafaelrglAuthor Commented:
Hi, is the agility Pac work on win32 applications because i am getting an error:

Error      1      Reference required to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the base class 'System.Object'. Add one to your project.

i already added the imports system.object and system.runtime and still the same error.
0
 
CodeCruiserCommented:
So yours is a 64bit application?
0
 
rafaelrglAuthor Commented:
yeap.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now