来自html页面的sed提取链接

时间:2014-09-05 16:29:04

标签: shell sed

我正在尝试使用 plowshare 编写上传模块,但我在上传页面解析时遇到问题。

我需要提取upload_url

<script type="text/javascript">

  upload_url: "http://s73.domain.com/?action=uploadfiles&user_id=TVRnN21ESX2c&secret_code=f4r6w35q639ih7oi62u674ae91453697", // Relative to the SWF file (or you can use absolute paths)

登录后,我加载页面进行上传,然后我需要提取upload_url

我尝试:

'upload_url:' '"\([[:digit:]]|http[:]//[^ ])*'

但我收到此错误

sed: -e expression #1, char 60: Unmatched ( or \(

1 个答案:

答案 0 :(得分:1)

<强> sed的:

sed -nE 's/.*upload_url: "([^"]+).*/\1/p' filename

输出:

http://s73.domain.com/?action=uploadfiles&user_id=TVRnN21ESX2c&secret_code=f4r6w35q639ih7oi62u674ae91453697

<强>的grep:

grep -oP 'upload_url: "\K[^"]+' filename

<强> AWK:

awk -F "\"" '/upload_url/ {print $2}' filename