China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-14 23:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help, how to extract image addresses from web source files? View 3,229 Replies 8
Original Poster Posted 2007-01-22 06:35 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
<TR align=middle>
<TD align=left width=306>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>
<TD width="7%"><IMG height=25 src="http://www.pcpop.com/pp/images/pp4_r3_c3.gif" width=21 border=0></TD>
<TD vAlign=bottom width="90%" background=images/pp4_r3_c10.gif>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=ffffff_14 align=left height=22><STRONG><A class=ffffff_14 title=Beauty Amorous Feelings href="http://www.pcpop.com/pp/t007400212_12512_1.html" target=_blank>Beauty Amorous Feelings</A></STRONG></TD></TR></TBODY></TABLE></TD>
<TD width="3%"><A href="http://www.pcpop.com/pp/t007400212_12512_1.html" target=_blank><IMG height=25 src="http://www.pcpop.com/pp/images/pp4_r3_c12.gif" width=51 border=0></A></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>
<TD height=1></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>
<TD bgColor=#ffffff height=2></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>
<TD align=middle bgColor=#f2f2f2>
<TABLE cellSpacing=0 cellPadding=0 width=101 border=0>
<TBODY>
<TR>
<TD vAlign=top align=middle width=101 background=images/pp1_6.jpg height=132>
<TABLE cellSpacing=0 cellPadding=0 width=20 border=0>
<TBODY>
<TR>
<TD height=4></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=right><A href="http://union.soqii.com/page/01/" target=_blank><IMG height=120 src="http://img2.pcpop.com/ArticleImages/0x0/0/386/000386225.jpg" width=90 border=0></A></TD>
<TD width=6></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle bgColor=#ffffff height=40><A class=x434343 href="http://union.soqii.com/page/01/" target=_blank>Upcoming Temptation</A><BR><A class=x434343 href="http://union.soqii.com/page/01/" target=_blank>(632P)</A></TD></TR></TBODY></TABLE></TD>
<TD width=20 background=images/pp3_4.gif>&nbsp;</TD>
<TD align=middle bgColor=#f2f2f2>
<TABLE cellSpacing=0 cellPadding=0 width=101 border=0>
<TBODY>
<TR>
<TD vAlign=top align=middle width=101 background=images/pp1_6.jpg height=132>
<TABLE cellSpacing=0 cellPadding=0 width=20 border=0>
<TBODY>
<TR>
<TD height=4></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=right><A href="http://www.huzhai.com/bbs/" target=_blank><IMG height=120 src="http://img2.pcpop.com/ArticleImages/0x0/0/332/000332157.jpg" width=90 border=0></A></TD>
<TD width=6></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle bgColor=#ffffff height=40><A class=x434343 href="http://www.huzhai.com/bbs/" target=_blank>Sneak Shots of the Building Opposite</A><BR><A class=x434343 href="http://www.huzhai.com/bbs/" target=_blank>(354P)</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>
<TD height=2></TD></TR></TBODY></TABLE></TD>
<TD align=right width=306>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>
<TD width="7%"><IMG height=25 src="http://www.pcpop.com/pp/images/pp4_r3_c3.gif" width=21 border=0></TD>
<TD vAlign=bottom width="90%" background=images/pp4_r3_c10.gif>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=ffffff_14 align=left height=22><STRONG><A class=ffffff_14 title=Tingting Graceful href="http://www.pcpop.com/pp/t007400212_11894_1.html" target=_blank>Tingting Graceful</A></STRONG></TD></TR></TBODY></TABLE></TD>
<TD width="3%"><A href="http://www.pcpop.com/pp/t007400212_11894_1.html" target=_blank><IMG height=25 src="http://www.pcpop.com/pp/images/pp4_r3_c12.gif" width=51 border=0></A></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="99%" border=0>
<TBODY>
<TR>

[ Last edited by tianzizhi on 2007-1-22 at 06:44 AM ]
QQ:419503077
Floor 2 Posted 2007-01-22 06:54 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  This should be relatively easy to solve using regular expression matching with sed.
Floor 3 Posted 2007-01-22 07:23 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Post a piece of pure batch processing code:

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('findstr "http://.*gif" test.txt') do (
set "var=%%i"
set "var=!var: src=☆!"
set "var=!var:.gif"=☆!"
set "var=!var:*☆=!"
for /f "tokens=1 delims==☆" %%j in ("!var!") do echo %%~j.gif
)
pause
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 4 Posted 2007-01-22 07:41 ·  中国 广东 广州 天河区 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
HTML markup language seems to be quite lenient with lines, meaning all code can be written on the same line, and it's not unusual to have two image addresses guided by src in the same line. At this time, the code of namejm probably can only find the first one... I don't know much about the language of web pages, I wonder if I remembered wrong...
Floor 5 Posted 2007-01-22 07:44 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
thanks very much!
QQ:419503077
Floor 6 Posted 2007-01-22 08:15 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
sed "/http/s/.*\(http:\/\/.*\.gif\).*/\1/;/^http:/!d" test.txt
Floor 7 Posted 2007-01-22 08:43 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If there may be several gif links on the same line, then use the following code (to be compatible with the ampersand &, quotes are added to the result, and exclamation marks are still filtered out):

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('findstr "http://.*gif" test.txt') do (
set "var=%%i"
set "var=!var:"=!"
set "var=!var: src=☆!"
set "var=!var:.gif=★!"
call :pick-up "!var!"
)
pause
goto :eof

:pick-up
set "var=%var:*☆=%"
for /f "tokens=1 delims==★" %%j in ("%var%") do echo "%%j.gif"
set "str_tmp=%var:☆=%"
if not "%str_tmp%"=="%var%" goto pick-up
goto :eof
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 8 Posted 2007-02-04 00:13 ·  美国 缅因州
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
Notice the original poster's words ------- The image type is jpg, gif

@sed "/jpg\|gif/!d;s/.*src=\x22\(*\)\x22.*/\1/;/^http/!d" p.txt> temp.txt

Based on GNU sed 4.1.4

[ Last edited by amao on 2007-2-4 at 10:59 AM ]
Floor 9 Posted 2007-05-08 11:10 ·  中国 广东 中山 电信
初级用户
★★
Credits 127
Posts 62
Joined 2007-04-19 12:43
19-year member
UID 85744
Gender Male
Status Offline
Got something! '<' was not handled properly
Forum Jump: