Solved

how to find and get some part of text file

Posted on 2014-03-10
9
367 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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 8

Expert Comment

by:Mohit Vijay
Comment Utility
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 29

Expert Comment

by:anarki_jimbel
Comment Utility
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
Comment Utility
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
 
LVL 29

Expert Comment

by:anarki_jimbel
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
0
 
LVL 1

Author Comment

by:rafaelrgl
Comment Utility
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
Comment Utility
So yours is a 64bit application?
0
 
LVL 1

Author Comment

by:rafaelrgl
Comment Utility
yeap.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now