I’m working on a web scraper that sometimes needs to remember a particular page, then go to some other pages and then go back to that page. Currently I just save the URL of the page, but that doesn’t work for pages like Google Maps, where the URL is always the same.
I can see that the GoBack method does go back to the previous page, so somehow the WebBrowser remembers what the previous pages was. How can I do this manually? I could count how many pages have been visited since the page I want to go back to and then call GoBack as many times as necessary, but that’s pretty unreliable and un-elegant. So I wonder how could I implement a GoBackToAParticularPage method.
There is one thing I think would get me closer to a solution: saving the URL of all frames and then putting them back when going back to that page. I think that would solve at lease the Google Maps problems. I have not tested it yet. I don’t know exactly what would it be the proper way to do this. I would need to wait for the frames to exist before setting their URLs.
In case anyone else can benefit from it, here is how I ended up doing it. The only caveat is that if the travel log to has too many pages in between, the entry might not exist any more. There is probably a way to increase the history size, but since there have to be some limit, I use the
TravelLog.GetTravelLogEntriesmethod to see whether the entry still exists or not and if not, use the URL instead.Most of this code came from PInvoke.