- 전체
- Sample DB
- database modeling
- [표준 SQL] Standard SQL
- G-SQL
- 10-Min
- ORACLE
- MS SQLserver
- MySQL
- SQLite
- postgreSQL
- 데이터아키텍처전문가 - 국가공인자격
- 데이터 분석 전문가 [ADP]
- [국가공인] SQL 개발자/전문가
- NoSQL
- hadoop
- hadoop eco system
- big data (빅데이터)
- stat(통계) R 언어
- XML DB & XQuery
- spark
- DataBase Tool
- 데이터분석 & 데이터사이언스
- Engineer Quality Management
- [기계학습] machine learning
- 데이터 수집 및 전처리
- 국가기술자격 빅데이터분석기사
- 암호화폐 (비트코인, cryptocurrency, bitcoin)
10-Min Programatically retrieving data from a website into a database
2017.05.30 22:27
Programatically retrieving data from a website into a database
pulse-grab-web-data (1).zip
by Matthew Moran | posted in: Microsoft Access, Programming, Video | 3
Summary: Our client wanted to extract data from a web portal. We wrote a VBA script to the requested information and store it in an Access database. The example below demonstrates the same technology, but the data is stored in Excel.
Edit: 9/9/2016: I posted a download to the file here.
Technologies
- Microsoft Access: Data and VBA
- Microsoft Internet Controls
- Microsoft HTML Document Control*
An understanding of the HTML Document Object Model (DOM) will help you A LOT.
Scrape web content using VBA
Screen scraping used to be a way to grab characters off of mainframes and AS/400’s. It is much easier to scrape web site information due to the DOM. Actually, it’s not scraping at all – more of a structured retrieval of data from HTML.
I cannot provide the exact code from the above project as it was a bought and paid for by our client and belongs to them. I’ll explain the methodology and provide sample code to retrieve web content. I’ll also demonstrate the retrieving information from the DOM.
I will provide the source code for you to retrieve information from my blog’s root page – the one listing the most recent 10 blog entries found at the link below:
http://www.pulseinfomatics.com/blog/
I’ll explain a couple critical differences in the code provided and the code we built for our client.
Create an Access table: tblWebData
With the following fields:
- wd_uno (autonumber, key)
- ArticleTitle (Short Text, 255)
- ArticleURL (Short Text, 255)
- ArticleAuthor (Short Text, 255)
- ArticleSummary (Long Text)
- DateRetrieved (date/time)
Note, I would size them differently but I was in a hurry. I’ll leave that to you.
Create an Access form (frmWebTest)
I put a single button on the form:btnGetWebData
This is the code for that button plus another sub-routine.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
FixQuotes Function
Variations of this functionality can be found in various places around the web. I grabbed mine from this blog.
http://mikeperris.com/access/escaping-quotes-Access-VBA-SQL.html
It ensures you don’t get errors when trying to save text with quotes.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Some DOM elements and nesting explained
My goal is not to teach you how to navigate the DOM. You can start here to learn more about the DOM.
intNumA = iHTML.getElementsByTagName(“article”).length
Returns the number of “article” tags on the page. For my blog, each article is contained in an article tag.
GetElementsByTagName(“article”)
Returns an array of any elements with the tag name (“article”)
You can now loop through each article to retrieve article-specific data.
iHTML.GetElementsByTagName(“article”).Item(x – 1)
Refers to a specific article tag and it’s associated HTML. x started counting 1. Arrays start at 0. x – 1 ensures you are referring to the correct article tag.
Once you refer to a specific article (x – 1) the objects you refer to after that relate only to that specific article. Elements that are not encapsulated (nested) in that “article” tag are ignored. Remember that when reading the href and innerTEXT references below.
.getElementsByTagName(“a”).Item(0).href
The first a tag href is the link to the blog entry.
The second href is the blog author. Subsequent hrefs, if they exist, link to categories. But I am only concerned with item(0) and item(1).
The innerTEXT of each hrefs returns the linked text. The article URL’s innerTEXT is the title. The author URL’s innerTEXT is the author name.
getElementsByTagName(“p”).Item(0).innerText
References the only paragraph in each article, the summary text.
That gives you some idea of how to reference items in the HTML Document Object Model.
How my client’s project differed.
In order to retrieve several pages of profiles, I had to:
- navigate to a page
- loop through information from a list
- present the user information and choices as to what they wanted to copy
- retrieve the data from a list
- navigate to sub-pages if they exist
- retrieve information from sub-pages
- move to the next page and repeat
Example Video
Here’s an example where I navigate the DOM on our website
Download File
You can get an Access file with the working code here.
[출처] https://www.pulseinfomatics.com/programatically-retrieving-data-from-a-website-into-a-database/
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 공지 | 오라클 기본 샘플 데이터베이스 | 졸리운_곰 | 2014.01.02 | 86127 |
| 공지 | [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE | 가을의 곰을... | 2013.02.10 | 78631 |
| 공지 | [G_SQL] Sample Database | 가을의 곰을... | 2012.05.20 | 95349 |

