ESPN 实况转播中一系列赛事的网络抓取图片 URL
Web Scraping Image URL for a series of events in ESPN Play-By-Play
我正在尝试使用网络抓取从 ESPN 生成逐场比赛数据集。我已经弄清楚了其中的大部分内容,但一直无法分辨该活动是为哪支球队举办的,因为这仅以图像形式在 ESPN 上进行了编码。我想出的解决此问题的最佳方法是获取每个条目的徽标的 URL,并将其与页面顶部每个团队的徽标的 URL 进行比较。但是,我一直无法弄清楚如何从图像中获取 url 等属性。
我在 R 上 运行 并且正在使用 rvest 包。我正在抓取的 url 是 https://www.espn.com/mens-college-basketball/playbyplay?gameId=400587906,我正在使用 SelectorGadget Chrome 扩展抓取。我也试过将球员的名字与 boxscore 进行比较,其中列出了所有球员,但每支球队都有一名姓琼斯的球员,所以我更希望能够通过查看图像,因为这永远是正确的。
library(rvest)
url <- "https://www.espn.com/mens-college-basketball/playbyplay?gameId=400587906"
webpage <- read_html(url)
# have been able to successfully scrape game_details and score
game_details_html <- html_nodes(webpage,'.game-details')
game_details <- html_text(game_details_html) %>% as.character()
score_html <- html_nodes(webpage,'.combined-score')
score <- html_text(score_html)
# have not been able to scrape image
ImgNode <- html_nodes(webpage, css = "#gp-quarter-1 .team-logo")
link <- html_attr(ImgNode, "src")
对于每个事件,我希望将其标记为 "Duke" 或 "Wake Forest"。
有没有办法为每个图像生成 URL?任何帮助将不胜感激。
"https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/150.png&h=100&w=100"
“https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/154.png&h=100&w=100”
你的代码returns这些。
500/150 是杜克大学,500/154 是维克森林大学。您可以使用这些创建一个简单的数据框,然后加入表格。
link_df <- as.data.frame(link)
link_ref_df <- data.frame(link = c("https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/150.png&h=100&w=100", "https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/154.png&h=100&w=100"),
team_name = c("Duke", "Wake Forest"))
link_merged <- merge(link_df,
link_ref_df,
by = 'link',
all.x = T)
如果您与其他团队一起做数百个这样的事情,这不可扩展,但适用于这个特定选项。
我正在尝试使用网络抓取从 ESPN 生成逐场比赛数据集。我已经弄清楚了其中的大部分内容,但一直无法分辨该活动是为哪支球队举办的,因为这仅以图像形式在 ESPN 上进行了编码。我想出的解决此问题的最佳方法是获取每个条目的徽标的 URL,并将其与页面顶部每个团队的徽标的 URL 进行比较。但是,我一直无法弄清楚如何从图像中获取 url 等属性。
我在 R 上 运行 并且正在使用 rvest 包。我正在抓取的 url 是 https://www.espn.com/mens-college-basketball/playbyplay?gameId=400587906,我正在使用 SelectorGadget Chrome 扩展抓取。我也试过将球员的名字与 boxscore 进行比较,其中列出了所有球员,但每支球队都有一名姓琼斯的球员,所以我更希望能够通过查看图像,因为这永远是正确的。
library(rvest)
url <- "https://www.espn.com/mens-college-basketball/playbyplay?gameId=400587906"
webpage <- read_html(url)
# have been able to successfully scrape game_details and score
game_details_html <- html_nodes(webpage,'.game-details')
game_details <- html_text(game_details_html) %>% as.character()
score_html <- html_nodes(webpage,'.combined-score')
score <- html_text(score_html)
# have not been able to scrape image
ImgNode <- html_nodes(webpage, css = "#gp-quarter-1 .team-logo")
link <- html_attr(ImgNode, "src")
对于每个事件,我希望将其标记为 "Duke" 或 "Wake Forest"。
有没有办法为每个图像生成 URL?任何帮助将不胜感激。
"https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/150.png&h=100&w=100" “https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/154.png&h=100&w=100”
你的代码returns这些。 500/150 是杜克大学,500/154 是维克森林大学。您可以使用这些创建一个简单的数据框,然后加入表格。
link_df <- as.data.frame(link)
link_ref_df <- data.frame(link = c("https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/150.png&h=100&w=100", "https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/154.png&h=100&w=100"),
team_name = c("Duke", "Wake Forest"))
link_merged <- merge(link_df,
link_ref_df,
by = 'link',
all.x = T)
如果您与其他团队一起做数百个这样的事情,这不可扩展,但适用于这个特定选项。