Power BI/R – Web Scraping (a full page with images)

In a previous blog, you learned how to scrape a webpage by using the web connector in Power BI with the CSS selector (Add table using examples) and how to import URLs of images with a trick in Power Query.
Today, I will show you how to import all information from the same webpage by using a R-script in Power BI and add these information into a nice visualization (Card Browser).

In order to use this tutorial, you must have R installed in your computer and the package RVEST also installed in you R environment.

In Power BI, select Get DataR script then paste the following code into the box :


UAR_wbpg = read_html("http://www.uar.dz/adherents-de-luar/")
companies = UAR_wbpg %>% html_nodes("h3") %>% html_text()
details = UAR_wbpg %>% html_nodes("div.tx-row") %>% html_nodes("ul") %>% html_nodes("li") %>% html_text()
Images = UAR_wbpg %>%  html_nodes("img") %>% html_attr("src")

details = details[-c(205,206)]
details = matrix(details, nrow=11, ncol = 23)
companies = companies[-c(24:31)]
Images = Images[-c(1,2)]

FinalTable = data.frame(companies, Images, t(details))

After the execution of the script, you get a table with all the information in the webpage as shown hereafter :

After making some cleaning in Power Query, in the Report Tab, we add the custom visual « Card Browser » and fill the properties like this:

And that’s it 👌, you will get a very nice presentation of all the imported information.
If you want to download the final Pbix, just ask for it in the comment. I hope that you enjoyed this tutorial and see you in the next blog 😊


4 commentaires sur “Power BI/R – Web Scraping (a full page with images)


Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l'aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s