如何 select 使用 Xidel 从文件中抓取哪一行?

How to select which line to scrape from a file with Xidel?

如果您的文本文件 file.txt 包含多行文本,例如

asd asd
asdasd asdasd

我要如何select抓取第2行asdasd asdasd? select 稍后的第 1 行等等

for /f %a in ('^" xidel --data=file.txt --extract=$raw ^"') do set "variable=%a" 仅提取第一行的第一个单词,它会跳过第一个空格之后的内容?

首先,不需要指定 --data

xidel --help | FIND "--data"
--data=<string>                         Data/URL/File/Stdin(-) to process
                                        (--data= prefix can be omitted)

How do I select that I want to scrape line 2 asdasd asdasd? And select line 1 later on etc.

您可以使用 x:lines($raw)。它是 tokenize($raw,'\r\n?|\n') 的 shorthand 并将 $raw 变成一个序列,其中每个新行都是另一个项目。然后简单地 select 第 1st,或 2nd 项:

xidel -s file.txt -e "x:lines($raw)[2]"
asdasd asdasd

for /f %a in ('^" xidel --data=file.txt --extract=$raw ^"') do set "variable=%a" extracts only first word from first line, it skips what's after the first whitespace?

因为如果不设置分隔符,则默认为<space><tab>:

FOR /? | FIND "delimiter"
        delims=xxx      - specifies a delimiter set.  This replaces the
                          default delimiter set of space and tab.

所以你可以这样做:

FOR /F "delims=" %A in ('xidel -s file.txt -e "x:lines($raw)[2]"') DO SET variable=%A

或者用xidel导出变量:

FOR /F "delims=" %A in ('xidel -s file.txt -e "variable:=x:lines($raw)[2]" --output-format^=cmd') DO %A