0

I have a data.frame:

structure(list(image_url = c("https://s.yimg.com/rz/stage/p/yahoo_news_en-US_h_p_newsv2.png", 
"https://s.yimg.com/ny/api/res/1.2/a9tDDXTQwXLiGSngH6UdPw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTEwMDtoPTQw/https://s.yimg.com/os/creatr-uploaded-images/2021-03/e31acf60-80f5-11eb-9fff-18c6b7043df9", 
"https://s.yimg.com/ny/api/res/1.2/Vq.ekgX6ZBXvVCQh24vhqg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MA--/https://s.yimg.com/uu/api/res/1.2/2ao_.pdKosXDhnURX7sXhA--~B/aD01MTI7dz03Njg7YXBwaWQ9eXRhY2h5b24-/https://media.zenfs.com/en/afp.com/1ea343da7418d350c00a1da7d95ca9d3", 
"https://s.yimg.com/ny/api/res/1.2/7UiD.SaHA.kzuP1DSn4G1A--/YXBwaWQ9aGlnaGxhbmRlcjt3PTM0O2g9NDA-/https://s.yimg.com/os/creatr-uploaded-images/2020-12/9b2f0f90-355f-11eb-bef3-afd1c608253f", 
"https://s.yimg.com/ny/api/res/1.2/rV7HIRh_EFzR7kNYNtTavA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQzMi42MjI4MjU0NjM1ODI1/https://s.yimg.com/uu/api/res/1.2/iRuML8_Vl85HgyfZHZjM.A--~B/aD0zMjEwO3c9NTIzMTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/cd329bbe2ed706c65ab70fe227819b90", 
"https://s.yimg.com/ny/api/res/1.2/p7desY4o1vEDB52CUbBzZw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ2OC4yODkyMTI0NDIwOTEzNQ--/https://s.yimg.com/uu/api/res/1.2/W.IxH0.ad0guC6n6WXECBg--~B/aD0zMDExO3c9NDUzMzthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/4bf556b19ba7aa9bf9f4d27b8a4c3bdf", 
"https://s.yimg.com/ny/api/res/1.2/.v5QW6ldbWSZ3cJQxdiJLg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ2OS44MjYxMDYyNjAxNzQ2NA--/https://s.yimg.com/uu/api/res/1.2/vprcE1ISfb5YlF0LgmbxAA--~B/aD00NTAzO3c9Njc1NzthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/9ce7bea825c46fa4507b244b769827a8", 
"https://s.yimg.com/ny/api/res/1.2/LnBoZRHhzr9O_JwrVxRQiQ--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ1Mi44MjY5MjMwNzY5MjMx/https://s.yimg.com/uu/api/res/1.2/W3a.0MVH784d91Gr2J27Uw--~B/aD0yMTcxO3c9MzM4MDthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/e6e3f689d9e20c34912801bdf59a4a4a", 
"https://s.yimg.com/ny/api/res/1.2/iC_0G1aPnL5Fxe.WsEhHAQ--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQwMC41NjQzMDEyODM2MDM3NQ--/https://s.yimg.com/uu/api/res/1.2/xLoNFIfa0LyirLXqIxOw8Q--~B/aD0yMzQ2O3c9NDEyOTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/34ff9da35a986f8317158c59eb147c41", 
"https://s.yimg.com/ny/api/res/1.2/yHLdNtpWuunjl_3hsi2irA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQxOS4yODcxNDczMzU0MjMy/https://s.yimg.com/uu/api/res/1.2/zISH6GY.GeMXIPbH5cT1LA--~B/aD00NzQzO3c9Nzk3NTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/0e46ec4bab9fc47a71d69be283b4a807", 
"https://s.yimg.com/ny/api/res/1.2/XBdRreRRdjr6WFiZOFbMHw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQzNi42NzA5NjQ0MTQ2NDY3Mw--/https://s.yimg.com/uu/api/res/1.2/7nY1TvLO3_YM3l_TmK144w--~B/aD0yNDAyO3c9Mzg3ODthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/4cb766a7d1acb63aff8662168f971a10", 
"https://s.yimg.com/ny/api/res/1.2/lJqBZ2Jd9iM4O6CDHX3Z7w--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQyMC4xMzE5OTY1Mzc3OTU3/https://s.yimg.com/uu/api/res/1.2/HYDyPZwdhycV0U2Q8d2_Bw--~B/aD00MTMxO3c9NjkzMjthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/2a42ec94fb335952cb8ace2587263974", 
"https://s.yimg.com/ny/api/res/1.2/06ClhwjvxvxgDOVjug3ivA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ1Ny45ODA1OTk2NDcyNjYzMw--/https://s.yimg.com/uu/api/res/1.2/A.reLiGwqkx20flV16lOaA--~B/aD0yMjEwO3c9MzQwMjthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/a7102be8b2ddd424b9639a92dc6bb909", 
"https://s.yimg.com/ny/api/res/1.2/hkFFt3ffISztLCmE1Fre2Q--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MC40NDA0ODczNDc3MDM4/https://s.yimg.com/uu/api/res/1.2/BTH8ORU5IZj41RLTRQl6Ew--~B/aD0xNDI0O3c9MjEzNDthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/962a4d0be64e8b9212436f2144db1c9d", 
"https://s.yimg.com/ny/api/res/1.2/X4B6hlWNS5RiBKjZSC99HA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ2My4zMTQ4NTA1MzAzNzYx/https://s.yimg.com/uu/api/res/1.2/prcDMjqtfEYNAUfh2GSGAQ--~B/aD0xMzYzO3c9MjA3NDthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/4a7f48464e95f319d7edf3957b3271fd", 
"https://s.yimg.com/ny/api/res/1.2/AOdXSJMMCj2LMYr9brEXHA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ0MS4zNjk1ODI5OTI2NDE-/https://s.yimg.com/uu/api/res/1.2/VOJoI.WQlajm9qrxTqc9cw--~B/aD0yMjk3O3c9MzY2OTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/9b45dc931f64836101ce4de1f2f1dca3", 
"https://s.yimg.com/ny/api/res/1.2/.OD_oNvh3oWi6o2IbnpBSA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ2My45NTA3NTU0NTYwNzE2NQ--/https://s.yimg.com/uu/api/res/1.2/SJctAlwF52BA7ugCguJ34w--~B/aD0zNTI4O3c9NTM2MTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/c0b2c3f5dc7e6f3230d5143583b746bc", 
"https://s.yimg.com/ny/api/res/1.2/MP9VK9vk7PPsCPrH_jTZsQ--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ5NS43NjY4ODEwMjg5Mzg5/https://s.yimg.com/uu/api/res/1.2/ITt9Mp8siLvJCBE8ipEJkg--~B/aD0yMTg3O3c9MzExMDthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/8602558d9aa474f51f72c341cfb10c00", 
"https://s.yimg.com/ny/api/res/1.2/8cjLjIhFjrKZ6OwGJU2sbw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ2Ny45MzI3MDI4ODEwMjA1/https://s.yimg.com/uu/api/res/1.2/K.bQC2b3OOhlNh0OyY.78Q--~B/aD0zMDE4O3c9NDU0NzthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/439564f50fbeae87caf2d96f5203d743", 
"https://s.yimg.com/ny/api/res/1.2/z4fgfqOwj2DxH9ak9Ap3BQ--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MA--/https://s.yimg.com/uu/api/res/1.2/7GJPiM3TRPf.9ch004yLfQ--~B/aD0zMjg4O3c9NDkzMjthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/4e113bca753c61164b91545b18bab4be", 
"https://s.yimg.com/ny/api/res/1.2/i298HHtl.TV3OoYSI0m6hg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MA--/https://s.yimg.com/uu/api/res/1.2/kdkTZ1ZZyRyhlIKlvGoQ1w--~B/aD0zMzUyO3c9NTAyODthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/8f4bd066d3fa20097f19db43d3de6393", 
"https://s.yimg.com/ny/api/res/1.2/CXCBuif1kK7k6gUJrQ6Bpg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MC4wNDY1NjIzMTQyNDYx/https://s.yimg.com/uu/api/res/1.2/Fj4R.YGpIQqrDCwTWPOoAA--~B/aD0zMzY1O3c9NTA0NzthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/301d0b992dde668ad1f4f37122a191dd", 
"https://s.yimg.com/ny/api/res/1.2/d0eFbJgZ1vXYrKPy53nvvQ--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTExMjMuNDE3MTg2MTA4NjM3Nw--/https://s.yimg.com/uu/api/res/1.2/XB.Lb9l3PdMJ1pU.Pa5efw--~B/aD0zNTc5O3c9MjI0NjthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/d472568f81fc4ba289119ae142fe547a", 
"https://s.yimg.com/ny/api/res/1.2/paHK_ywUjkJRPVgT3dnnlg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MA--/https://s.yimg.com/uu/api/res/1.2/toPioD68IchIJTlfr_Tqrw--~B/aD0zMjMwO3c9NDg0NTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/a5ccfbb650d5d30d759b9c65d6b41a2b", 
"https://s.yimg.com/ny/api/res/1.2/l.7yp_Knalvc6aNQQxl1rA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MC4wNDE0NjA4MzI3NDUyNg--/https://s.yimg.com/uu/api/res/1.2/xgk0igSQXKnoTOnQB.QGUQ--~B/aD0zNzc5O3c9NTY2ODthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/53c2173124b66e09217937e37e0b568f", 
"https://s.yimg.com/ny/api/res/1.2/BYRbzLKUCwTwQVxBjD7G2w--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MA--/https://s.yimg.com/uu/api/res/1.2/2ry0F_3Ecez8K4UMcGildw--~B/aD0yMzI4O3c9MzQ5MjthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/b88bd433a8265046e29e11ea1561ba93", 
"https://s.yimg.com/ny/api/res/1.2/FA4ImziM6hNsGAmSbs_xPw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MC4wMzE4OTAzNTE0NzI0/https://s.yimg.com/uu/api/res/1.2/ys_xJ5hycdIuPJFV8BQsmA--~B/aD00OTEzO3c9NzM2OTthcHBpZD15dGFjaHlvbg--/https://media.zenfs.com/en/ap.org/7d0a5a9a254d398476f666e9f7253d2b", 
"https://s.yimg.com/ny/api/res/1.2/ZcRpqUj7ALE9pVlAfaOsVw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTE3MjtoPTQw/https://s.yimg.com/os/creatr-uploaded-images/2020-11/62e21440-2fbd-11eb-95ff-5673fa3d2f9f", 
"https://s.yimg.com/ny/api/res/1.2/oWI5jEEXxruFi7UoNCWcpQ--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ0My4yNjg3NQ--/https://s.yimg.com/uu/api/res/1.2/prWfZp2jlEC3eQNTyeHySg--~B/aD01MDM7dz04MDA7YXBwaWQ9eXRhY2h5b24-/https://media.zenfs.com/en/reuters.com/de795cc0b3e8191f69846d3c0091009a", 
"https://s.yimg.com/ny/api/res/1.2/lPdC4_UP6TAD1sGfBKJ85A--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ2MC4wMTI1/https://s.yimg.com/uu/api/res/1.2/Zj9J2L8F9zX5H9G516b4Mg--~B/aD01MjI7dz04MDA7YXBwaWQ9eXRhY2h5b24-/https://media.zenfs.com/en/reuters.com/81cee58f4d1720663ca969a18b28ca8f", 
"https://s.yimg.com/ny/api/res/1.2/o3upOLh_xSVAahXgTovLLg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTE4ODtoPTQw/https://s.yimg.com/os/creatr-uploaded-images/2021-02/d6cfeca0-6bdc-11eb-9fff-072dbeffa160", 
"https://s.yimg.com/ny/api/res/1.2/dkf_LrzFkTfEP9Bhm8DRSA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTgwO2g9ODA-/https://s.yimg.com/os/creatr-uploaded-images/2019-02/c51f2780-3b70-11e9-bfbf-733751ce931b", 
"https://s.yimg.com/ny/api/res/1.2/vU2CD2jrt5YhTKcVzvWtaA--/YXBwaWQ9aGlnaGxhbmRlcjt3PTcwNTtoPTQ3MA--/https://s.yimg.com/os/creatr-uploaded-images/2021-06/28901630-c463-11eb-bf36-51cd40e50f37", 
"https://a.espncdn.com/combiner/i?img=/photo/2021/0606/r863740_1296x1296_1-1.jpg&w=130&h=130&scale=crop&location=center", 
"https://s.yimg.jp/images/news/cobranding/thedigest.png", "https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210607-00042237-thedigest-000-2-view.jpg?w=640&h=428&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000013-jct-000-3-view.jpg?w=264&h=264&cx=33&cy=0&cw=1467&ch=1467&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000143-dal-000-7-view.jpg?w=264&h=264&cx=120&cy=0&cw=720&ch=720&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000504-nnn-000-1-view.jpg?w=264&h=264&cx=57&cy=0&cw=450&ch=450&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000011-kyodonews-000-50-view.jpg?w=264&h=264&cx=0&cy=150&cw=620&ch=620&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000100-jij-000-4-view.jpg?w=264&h=264&cx=0&cy=116&cw=792&ch=792&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00848427-number-000-6-view.jpg?w=264&h=264&cx=70&cy=0&cw=480&ch=480&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00848406-number-000-5-view.jpg?w=264&h=264&cx=160&cy=0&cw=480&ch=480&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210611-00000089-sasahi-000-5-view.jpg?w=264&h=264&cx=0&cy=0&cw=860&ch=860&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00166544-theanswer-000-1-view.jpg?w=264&h=264&cx=104&cy=0&cw=600&ch=600&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00166559-theanswer-000-1-view.jpg?w=264&h=264&cx=173&cy=0&cw=600&ch=600&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210607-00000002-fliv-000-1-view.jpg", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000000-fliv-000-1-view.jpg?w=264&h=264&cx=75&cy=0&cw=300&ch=300&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000004-msportcom-000-2-view.jpg?w=264&h=264&cx=400&cy=0&cw=800&ch=800&order=c2r&q=90&exp=10800&pri=l", 
"https://amd-pctr.c.yimg.jp/r/iwiz-amd/20210614-00000012-msportcom-000-1-view.jpg?w=264&h=264&cx=200&cy=0&cw=800&ch=800&order=c2r&q=90&exp=10800&pri=l"
), article_url = c("https://news.yahoo.com/angry-wolff-humbled-hamilton-mercedes-105317797.html", 
"https://news.yahoo.com/angry-wolff-humbled-hamilton-mercedes-105317797.html", 
"https://news.yahoo.com/angry-wolff-humbled-hamilton-mercedes-105317797.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/perez-wins-azerbaijan-gp-verstappen-142853215.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/former-f1-drivers-see-european-070738314.html", 
"https://news.yahoo.com/f1-race-singapore-canceled-over-173003544.html", 
"https://news.yahoo.com/motor-racing-singapore-grand-prix-143022323.html", 
"https://news.yahoo.com/motor-racing-singapore-grand-prix-143022323.html", 
"https://news.yahoo.com/motor-racing-bottas-raised-concerns-175821962.html", 
"https://news.yahoo.com/formula-1-azerbaijan-betting-preview-is-this-valtteri-bottas-week-to-win-120228018.html", 
"https://news.yahoo.com/formula-1-azerbaijan-betting-preview-is-this-valtteri-bottas-week-to-win-120228018.html", 
"https://news.yahoo.com/formula-1-azerbaijan-betting-preview-is-this-valtteri-bottas-week-to-win-120228018.html", 
"https://www.espn.com/f1/story/_/id/31584484/vettel-reborn-aston-martin-says-brawn", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/001ca55c371c15b11b5d9e4cc2495e5e717fd7c8", 
"https://news.yahoo.co.jp/articles/62b462e62b60a2188f74497e53ffc5885b8d90c9", 
"https://news.yahoo.co.jp/articles/62b462e62b60a2188f74497e53ffc5885b8d90c9", 
"https://news.yahoo.co.jp/articles/62b462e62b60a2188f74497e53ffc5885b8d90c9", 
"https://news.yahoo.co.jp/articles/62b462e62b60a2188f74497e53ffc5885b8d90c9"
), Article_ID = c("Azerbaijan1", "Azerbaijan2", "Azerbaijan3", 
"Azerbaijan4", "Azerbaijan5", "Azerbaijan6", "Azerbaijan7", "Azerbaijan8", 
"Azerbaijan9", "Azerbaijan10", "Azerbaijan11", "Azerbaijan12", 
"Azerbaijan13", "Azerbaijan14", "Azerbaijan15", "Azerbaijan16", 
"Azerbaijan17", "Azerbaijan18", "Azerbaijan19", "Azerbaijan20", 
"Azerbaijan21", "Azerbaijan22", "Azerbaijan23", "Azerbaijan24", 
"Azerbaijan25", "Azerbaijan26", "Azerbaijan27", "Azerbaijan28", 
"Azerbaijan29", "Azerbaijan30", "Azerbaijan31", "Azerbaijan32", 
"Azerbaijan33", "Azerbaijan34", "Azerbaijan35", "Azerbaijan36", 
"Azerbaijan37", "Azerbaijan38", "Azerbaijan39", "Azerbaijan40", 
"Azerbaijan41", "Azerbaijan42", "Azerbaijan43", "Azerbaijan44", 
"Azerbaijan45", "Azerbaijan46", "Azerbaijan47", "Azerbaijan48", 
"Azerbaijan49", "Azerbaijan50"), img_ID = c("img1", "img2", "img3", 
"img4", "img5", "img6", "img7", "img8", "img9", "img10", "img11", 
"img12", "img13", "img14", "img15", "img16", "img17", "img18", 
"img19", "img20", "img21", "img22", "img23", "img24", "img25", 
"img26", "img27", "img28", "img29", "img30", "img31", "img32", 
"img33", "img34", "img35", "img36", "img37", "img38", "img39", 
"img40", "img41", "img42", "img43", "img44", "img45", "img46", 
"img47", "img48", "img49", "img50")), row.names = c(NA, 50L), class = "data.frame")

I have a code that loops through these urls and downloads the pictures from scraped image URLs:


try(sapply(1:NROW(total_urls.2$image_url), function(x) 
download.file(total_urls.2[[x,1]],paste0(total_urls.2[x,3],"_", total_urls.2[x,4],".png"),method = "auto" ,mode = "ab", cacheOK = TRUE)),silent = TRUE)

The current dataset used in this will draw a "404 error" at row 37. How do I create an error function that will just skip to the next row and continue downloading. I would also like this to skip rows that do not have a downloadable content. The latter occurs when doesnt cause an error but it does stop the process...the dataset is much larger and I usually have to manually filter out the bad urls or subset the df past the error row(s)

d3hero23
  • 380
  • 1
  • 12
  • 1
    The `try` needs to be inside your inner function, not outside the `sapply` – MrFlick Jul 19 '21 at 19:40
  • @MrFlick could you please alter my code to demonstrate what you are referring to? – d3hero23 Jul 19 '21 at 19:44
  • This is not working...DL_function<-function(x,df) { return( tryCatch( download.file(df[x,1],paste0(df[x,3],"_", df[x,4],".png"),method = "auto" ,mode = "ab", cacheOK = TRUE), error=function(e) NULL)) } – d3hero23 Jul 19 '21 at 20:09
  • @MrFlick sapply(1:NROW(total_urls.2$image_url), DL_function(x, total_urls.2)) Error in match.fun(FUN) : 'DL_function(x, total_urls.2)' is not a function, character or symbol.................When I define the second variable within the function it works so .... sapply(1:NROW(total_urls.2$image_url), DL_function(x, total_urls.2)) this works. but I dont want to have to define it in the function because I want to reuse this function 3x – d3hero23 Jul 19 '21 at 20:34
  • 1
    You need to pass a function to `sapply`, not call a function. You can try `sapply(1:NROW(total_urls.2$image_url), function(x) DL_function(x, total_urls.2))` or `sapply(1:NROW(total_urls.2$image_url), DL_function, df=total_urls.2)` – MrFlick Jul 19 '21 at 20:35
  • @MrFlick is there a way to have the error function spit which rows did not download in a list in the globalenviornment... it spits out a list in console only – d3hero23 Jul 21 '21 at 14:42

0 Answers0