使用R刮擦,只在列表中抓取第一个实例[关闭](Scraping with R, only first instance being scraped in the list [closed])
我已经抓了几个网站,并没有真正对我的输出有问题,但我不明白为什么在这个特定的网站上我只得到我试图刮去而不是所有36的第一个实例。
我正在尝试收集页面上所有玩家的
href
链接,并将它们保存到列表或数据框中。我目前的代码是:
library(XML) library(rvest) match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922" WSm <- read_html(match) Players <- WSm %>% html_node(".player-name") %>% html_attr("href") %>% as.character()
这给了我:
[1] "/fotballdata/person/profil/?fiksId=2820074"
不是我所期望的所有玩家的所有
href
的完整列表。 谁能帮忙?I have scraped a few websites and haven't really had a problem with my outputs but I don't understand why on this particular website I am only getting the 1st instance of what I am trying to scrape instead of all 36.
I am trying to collect the
href
links for all players on the page and save them to a list or dataframe.My current code is:
library(XML) library(rvest) match <- "https://www.fotball.no/fotballdata/kamp/?fiksId=6616922" WSm <- read_html(match) Players <- WSm %>% html_node(".player-name") %>% html_attr("href") %>% as.character()
This gives me:
[1] "/fotballdata/person/profil/?fiksId=2820074"
Not the full list of all
href
s for all players as I am expecting. Could anyone help?
原文:https://stackoverflow.com/questions/39258944
最满意答案
尝试使用find :
find -iname makefile -execdir make -f {} \;
这将找到每个文件名为
makefile
(或Makefile,或者任何不同的单词makefile的情况,感谢thiton)(递归)然后启动make对它。Try with find :
find -iname makefile -execdir make -f {} \;
That will find every file named
makefile
(or Makefile, or whatever different case for word makefile, thanks to thiton) (recursively) and then launch make against it.
相关问答
更多-
这将递归为您做: find /path/to/base/dir/* -type d -ctime +10 -exec rm -rf {} \; 说明: find :查找文件/目录/链接等的unix命令 /path/to/base/dir :开始搜索的目录。 -type d :只找到目录 -ctime +10 :只考虑修改时间超过10天的那些 -exec ... \; :对于每个这样的结果,请在...执行以下命令 rm -rf {} :递归强制删除目录; {}部分是从上一部分找到结果的地方。 或者,使用: ...
-
如果当前目录包含目录“v_79”,那么 for dir in v_79/dir_{0..210}/ENSG00000??????; do mkdir $dir/my_dir; done 我想知道这是否会给你一个“参数列表太长”的错误,在这种情况下, find是要走的路。 if your current directory contains directory "v_79", then for dir in v_79/dir_{0..210}/ENSG00000??????; do mkdir $dir/m ...
-
你可以用find 。 myShell.sh脚本可能看起来有点像这样,这是一个递归处理目标下任何和所有子目录的版本。 DIR="$1" find "$DIR" -type d -exec java myProg {} \; 可用的确切find选项集取决于您的各种unix。 如果你不想要递归,你可以使用-maxdepth作为Neeraj注意到,或者也许-prune ,它开始变得有点难看: find "$DIR" \( ! -name . -prune \) -type d -exec java myProg ...
-
我的猜测是你要深入两个层次,但只能回到一个层次。 尝试在ls之后添加cd ../.. ,或者使用pushd和popd来代替。 例如: for dir in $dirlist do pushd $dir echo $dir ls popd done 正如@shellter指出的那样,如果这些目录有空格,那么类似这样的东西可能会更好: find $1 -mindepth 1 -maxdepth 1 -type d | while read -r dir do pushd "$dir" # ...
-
显示您所询问的信息的最简单方法是使用您希望以分层形式查看所有内容的目录中的$ tree命令。 如果还没有安装(如果使用linux应该是) $ sudo apt update $ sudo apt upgrade $ sudo apt install tree 如果使用mac $ brew update $ brew upgrade $ brew install tree 此命令将显示所有目录,即运行tree命令的目录下的子目录 希望这可以帮助 The easiest way to display th ...
-
它只保存脚本所在的目录: DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" commandA && commandB条件的计算方式如下: 当且仅当commandA返回退出状态为零时,才执行commandB 。 作为cd something ,如果dir存在,它将返回true。 如果不是,它将返回退出状态false,因此不会执行pwd 。 从图形上看,它可以解释为: DIR="$( cd "$( dirname "${BASH_SOURCE[0] ...
-
尝试使用find : find -iname makefile -execdir make -f {} \; 这将找到每个文件名为makefile (或Makefile,或者任何不同的单词makefile的情况,感谢thiton)(递归)然后启动make对它。 Try with find : find -iname makefile -execdir make -f {} \; That will find every file named makefile (or Makefile, or whate ...
-
在Unix上一次在多个目录中运行相同的shell脚本(Running the same shell script in multiple directories at once on Unix)[2023-12-09]
在csh : foreach d (case*) $d/script & end 或者您可以使用sh / bash ,它提供了更好的编程接口: for d in case*; do $d/script & done 如果要在执行脚本时进入目录,请在运行脚本之前添加cd 。 In csh: foreach d (case*) $d/script & end Or you can use sh/bash which gives a better programatic interface: for ... -
find命令在这些方面非常强大,请尝试: find videos/ -name "*.mp4" -exec ffmpegScript {} \; 这将查找.mp4结尾的所有文件(也在子目录中)并执行ffmpegScript nameOfMp4File ,其中nameOfMp4File是找到的文件的名称,一次一个。 find照顾循环本身。 现在我们需要定义ffmpegScript : #!/usr/bin/env bash inputFile="$1" outputFile="$(dirname $1)" ...
-
像/var/www/html/my.domain.com/v*这样的全局模式是一种bash功能。 当您使用sh script.sh启动脚本时,bash似乎不是系统上的默认shell。 确保使用bash启动脚本: bash script.sh 如果您要使用chmod +x script.sh直接使脚本可执行,请确保您不会错过在第一行中使用以下shebang : #!/bin/bash Glob patterns like /var/www/html/my.domain.com/v* are a bash ...