Solved

how to find and get some part of text file

Posted on 2014-03-10
9
405 Views
Last Modified: 2014-04-02
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
Comment
Question by:rafaelrgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 39918675
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
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 39918715
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
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39918754
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 39918837
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39921617
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39933353
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39940202
So yours is a 64bit application?
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39954398
yeap.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question