WebBrowser Display partial website - c#

I'm displaying a website in a C# WebBrowser. But I would like to display only the search part not the whole website so it won't bo so big on the screen. This is the website http://www.buscacep.correios.com.br/ and I would like to display only the Busca CEP - Endereço Box. Any ideas of how I can do this? I tryed to use htmlagilitypack but it has very little documentation and I couldn't understand it.

The WebBrowser control isn't really designed for what you're asking. You probably could go through all the page elements and remove anything that isn't part of the search box, but that's a lot of work for very little value.
However, there's a bright side. As mentioned in a comment, you should be able to POST directly to the search page. Use a program like Fiddler to find out what form values are being passed to the server with the request. Then you can re-create that request from your own application (using a WebClient or HttpClient). The result will be HTML, which you can display in your WebBrowser by setting the returned HTML to the WebBrowser's DocumentText property.

Related

Winforms control for displaying html text

I am coding a Windows Forms Application in C#, and one of the requirements is to display some html code in a control, with the correct colors that correspond to the relevant tags.
E.g. When right clicking on a webpage in Google Chrome, then selecting View Page Source, a form is shown with all the html, correctly formatted, with tag colors and each line of code's line number.
Is there a free, reliable control that can do this? Is there an inbuilt Microsoft control that does this?
As I am new to this area of coding, can someone please provide me with some useful names, and some resource links if possible? I am not sure of the correct name for a control that does this, and as such, my Google searches have not come up with what I am looking for.
Also, the control needs to be trustworthy.
Thanks
You can try ScintillaNET control. It's open source and has HTML syntax highlighting as well as many other features.

HTMLElement - Fill it and make it act as it was filled by a keyboard

I'm programming an autocomplete scraper in C# .Net 2.0. I tried a lot of tricks to make an Input Box on a specific website to show its autocomplete suggestions. Because I'm filling it with HtmlElement.SetAttribute("Blah"), it doesn't act as if I was filling it by hand, so it doesn't show the autocomplete suggestions
SendKeys is a very bad solution since it is imprevisible and crappy.
I tried HtmlElement.InvokeMember("WithEveryOptionPossible") and it does nothing.
I tried the SendMessage PInvoke and I saw no impact on my WebBrowser.
Is there an existing solution to send a key or a virtual key to WebBrowser so I could trigger the autosuggestion of the input box?
[edit]
I've been able to see what is being fetching via Wireshark. Didn't think about it before. I only needed to convert and attach my WebBrowser cookie to a WebRequest cookie and use the direct autocomplete URL. Now I can fastly get autocomplete suggestions without Timer and SetAttribute. (Until I get banned.) In fact, a WebBrowser is not needed anymore, since only a session-cookie is important, and no SetAttribute are needed. I think the former question has maybe no solution.

search text on web page

I am attempting to create a 'find on page' search option for a wp7 webbrowser control named 'TheBrowser' (using the standard webbrowser control in Visual Studio). I have done a lot of research but have not found much in the way of an example or sample where this was implemented. Essentially I will just be activating the search on a click event, from a textbox where the user may type in a word to search in the current webpage. I would also like to highlight the matched words as seen when doing a find on page search on a desktop browser.
I believe that to create this 'find on page' option I should use javascript to search through the lines of text, and then somehow highlight matched words. I have already implemented forward, back, and refresh buttons using TheBrowser.InvokeScript, but I do not know how to format for searching through the entire webpage (I have never done anything like this before). Any advice or assistance would be greatly appreciated, including code samples as I am completely new to this subject! Thanks in advance for your help and hard work!
Try jquery, this should do the trick: http://hugoware.net/blog/more-jquery-magic-search-highlighting You'll just need to inject the jquery script into the page.

How to get the HTML element in an new windows triggered by javascript?

i'm using WebBrowser control in Windows Forms App to automate a website and do some actions, so i need to know the HTML elements in the website(for example, textbox id, button id).
Everything is running smooth until i meet one situation. There are a html link element which point back to itself (eg: "http://www.aaa.com") but trigger a new windows with different url (eg: "http://www.bbb.com"). Below is the html link element :
< a href="#" class="toolbar" id="Export_Link" onclick="showExportWindow();" title="Export me">Exports & Reports< /a>
It showed up a new window with different url and therefore, the WebBrowser control unable to get the HTML element in the new window because it trace back the html element in the old window ("http://www.aaa.com#") and not the new window ("http://www.bbb.com")
Please help me! I'm stucking here for 1 weeks already! Anyone know how to solve this problem?
I'm not sure if i understand your problem correctly, but it seems that you are struggling with the "#" link. It's a common practice to link to the external page, even if you want to use javascript to open this page. This provides a good fallback for browsers with disabled javascript support.
Other
Pay regard to the return false; at the end of the javascript, it's necessary to tell the browser that the "normal" page link shouldn't be followed when the javascript runs.

Checking checkboxes with webbrowser element

Today i tried to write a program which checks some checkboxes for me on a webpage and then clicks on a button.
For this purpose i tried to use the webbrowser, but how can I set the state of a checkbox there? Searching the internet for hours but no luck only managed to navigate to the webpage with the checkboxes.
One approach would be to write a Bookmarklet, where you create a bookmark that runs JavaScript code, and the other would be to avoid the web browser altogether and instead just send a request directly to the web server that looks like it would if you had checked the checkboxes and clicked the button. Using a tool like wget or curl can make the latter option pretty easy.
Here's a sample URL that you could use to go for the Bookmarklet approach:
javascript:document.getElementById('theCheckBox').setAttribute('checked', 'checked');document.getElementById('theForm').submit();
The easiest way to do the second approach would be to use a tool like Firebug or Fiddler to monitor what a request looks like when you manually submit a page with your checkboxes checked and then construct similar requests through curl.
Using a WebBrowser control is not really a good approach here. The purpose of this control is to display a webpage, not to automate user interaction with it.
The most easy and most reliable solution is to use HttpWebRequest to directly talk to the server, sending a (most likely) POST request.

Categories