Please install the rvest package first.
library(rvest)
## Warning: package 'rvest' was built under R version 4.1.2
Get the HTML source file from the webpage:
url = "https://www.fbe.hku.hk/people/faculty?pg=1&staff_type=faculty&subject_area=marketing&track=all"
webpage = read_html(url, encoding = "UTF-8")
Find and print the text information:
image_nodes <- html_nodes(webpage,xpath = '//div/a/img[@width="800"]')
image_nodes <- html_nodes(webpage,xpath = '//div/a/img[@width="800"]')
for (image in image_nodes)
{
photourl <- html_attr(image, "data-src")
print(photourl)
}
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/52612/CAO-Jingcun_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11511/0HKU_2925_2019-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/8070/CHU_Buston_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11554/FBE_0712_web--scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/8059/Dr_Du_Jinzhou_2019-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/8072/HUANG_Tak_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11524/JIA_Shi_Jayson_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11544/Dr_Jia_He_Michael_2019-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/54087/DSC02191b_2-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/151668/Dr.-Bernard-Lee-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/148777/Li-Xi_2021-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/9174/0HKU_2266_2019-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11279/PHAN_Tuan_Quang_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/138621/Mr-Rach-Sean_0315-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11525/EchoWan_ProfilePhoto1_1563524057-scaled-800x800-ct.jpg"
number = 1
for (image in image_nodes)
{
photourl <- html_attr(image, "data-src")
print(photourl)
download.file(photourl, paste0(toString(number),'_HKU_Photo.jpg'), mode = 'wb')
number = number + 1
}
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/52612/CAO-Jingcun_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11511/0HKU_2925_2019-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/8070/CHU_Buston_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11554/FBE_0712_web--scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/8059/Dr_Du_Jinzhou_2019-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/8072/HUANG_Tak_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11524/JIA_Shi_Jayson_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11544/Dr_Jia_He_Michael_2019-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/54087/DSC02191b_2-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/151668/Dr.-Bernard-Lee-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/148777/Li-Xi_2021-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/9174/0HKU_2266_2019-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11279/PHAN_Tuan_Quang_web-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/138621/Mr-Rach-Sean_0315-scaled-800x800-ct.jpg"
## [1] "https://www.hkubs.hku.hk/wp-content/uploads/fly-images/11525/EchoWan_ProfilePhoto1_1563524057-scaled-800x800-ct.jpg"