需要使用curl来grep特定的字符串
我正在尝试通过 curl 从页面中获取语言代码
我写在下面并工作...
curl -Ls yahoo.com | grep "lang=" | head -1 | cut -d ' ' -f 3 | cut -d""" -f 2
但有时代码是不同的
curl -Ls stick-it.app | grep "lang=" | head -1 | cut -d ' ' -f 3 | cut -d""" -f 2
他们写道
<html dir="rtl" lang="he-IL">
我只需要得到 he-IL
如果有其他方法,我将不胜感激......
回答
在每个 Unix 机器上的任何 shell 中使用任何 sed:
$ curl -Ls yahoo.com | sed -n 's/^<html.* lang="([^"]*).*/1/p'
en-US