r/visualbasic • • Jun 05 '19

Save a webpage that uses Ajax

I run a number of programs that I've written to download and parse webpages, but pages that use Ajax are a problem. I find that using Chrome and saving the complete webpage will save an HTML file with the needed data, but communicating with Chrome is a problem. Has anyone been successful in integrating Chrome or other browser to be able to programmatically save an Ajax page?

6 Upvotes

4 comments sorted by

1

u/andrewsmd87 Web Specialist Jun 05 '19

You should be able to make a normal web request using VB to make the page respond as if you're requesting it in a browser. This can get tricky as automatically downloading html usually means you're trying to do something nefarious. What's your use case for this?

1

u/[deleted] Jun 05 '19

normal web request using VB to make the page respond as if you're requesting it in a browser.

Obviously, I've been doing this wrong. How does one make a request that will activate response to Ajax?

automatically downloading html usually means you're trying to do something nefarious

Heh. I understand that impression. I'm not even using it to download porn. No, I am deeply involved with travel and do like to follow multiple sites for information and rates in order to keep a database and to make summaries. I can keep much better track of fares and prices this way. For example, Delta has a page where they show their best bargain Skymiles fares, but it is populated through Ajax. I would love to be able to include this in my data.

2

u/andrewsmd87 Web Specialist Jun 05 '19

If you're looking for pricing info and what not, scraping html is going to be a bad way to do things because as soon as they make changes your scraper will either get bad info, get no info, or flat out break.

You're probably better off looking for free APIs out there that serve up this info.

That being said, if you REALLY want to parse html, then just google visual basic download html from web page. There are plenty of easy options out there

1

u/[deleted] Jun 05 '19

I can download the HTML and parse without problem. Been doing that a long time. The problem is with the dynamic content that is not downloaded with the HTML file.

because as soon as they make changes your scraper will either get bad info

Quite true. When they change format I need to retool, but fortunately I've developed pretty good tools for parsing the pages and that only takes minutes to change, provided they have not moved to dynamic content.