Chinaunix

标题: 怎么下载网页内容 [打印本页]

作者: smallstar001    时间: 2008-12-26 15:16
标题: 怎么下载网页内容
我有类似

http://172.16.28.110/mantis/view.php?id=49
http://172.16.28.110/mantis/view.php?id=42
http://172.16.28.110/mantis/view.php?id=14


很多,

我想下载它们的文本内容然后找我感兴趣的东西

我用
  1. wget [url]http://172.16.28.110/mantis/view.php?id=49[/url]
复制代码


下载的怎么没有文本内容。该如何解决?
作者: 我是DBA    时间: 2008-12-26 15:16
curl -d "username=用户名&password=密码&button=登录" http://172.16.28.110/mantis/login_page.php
用这个试试:)
作者: 我是DBA    时间: 2008-12-26 15:23
使用curl
作者: haimming    时间: 2008-12-26 15:24
我有两个脚本,看看对你有没帮助

第一个知道最后一页页数

  1. #! /bin/bash
  2. #done book from url
  3. url="http://www.linuxsir.org/bbs/thread29701.html"
  4. urlbase=${url%/*}
  5. urlfile=${url##*/}
  6.     wget -q $url
  7.     w3m $urlfile >a

  8. count=2

  9.     urlfile=${urlfile%.*}-$count.html

  10. while [ $count -lt 12 ]
  11. do

  12.     wget -q $urlbase"/"$urlfile
  13.    
  14.     w3m $urlfile >>a
  15. #    cat a
  16.     rm $urlfile       
  17.     echo $count  $urlfile "##################"

  18.     ((count++))
  19.     urlfile=${urlfile%-*}-$count.html
  20. done
复制代码

第二个,是人家的,知道共同特征“下一节”

  1. #! /bin/bash
  2. #done book from url
  3. url="http://www.xunlei-mz.cn/artview_91842_6.html"
  4. urlbase=`echo ${url%/*}`
  5. urlfile=`echo ${url##*/}`
  6. count=0
  7. while(true)
  8. do
  9.     ((count++))
  10.     wget -q $urlbase"/"$urlfile
  11.     iconv -f gb18030 -t utf8 $urlfile >tmp.shtml
  12.    
  13.     w3m tmp.shtml >>a
  14. #    cat a
  15.     rm $urlfile       
  16.     urlfile=`grep "下一节" tmp.shtml |sed "s/'>.*//"|sed "s/.*'//"`
  17.     echo $count  $urlfile "##################"
  18.     if [ -z "$urlfile" ]
  19.     then
  20.         break   
  21.     fi  
  22. done
  23. rm tmp.shtml
复制代码

作者: 我是DBA    时间: 2008-12-26 15:26
[root@union rc.d]# curl www.chinaunix.net >unix.net
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 80371    0 80371    0     0  1067k      0 --:--:-- --:--:-- --:--:-- 1404k
[root@union rc.d]# cat unix.net |more
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<META
content="Linux,unix,Freebsd,Solaris,服务器,存储,数据库,开发,程序设计,网络,安全,备份,硬件,IT培训,IT招聘求职,IT业界,IT人物,IT评论,业界
评论,计算机,数码,IT圈,下载,wiki,blog,博客"
name=keywords>
<META
content="ChinaUnix.net是中国最大的Linux/Unix技术社区网站,我们还交流程序开发,数据库,存储备份,服务器技术,网络安全等技术,并提供IT人才招
聘,软件下载,BLOG,IT培训等服务。"
name=description>
<title>ChinaUnix.net = 全球最大的Linux/Unix应用与开发者社区 = IT人的网上家园</title>
<meta http-equiv="Refresh" content=300;URL=/>
<meta name="robots" content="ALL">
<meta name="distribution" content="Global">
<meta name="rating" content="General">
<meta name="author" content="http://www.chinaunix.net/">
<meta name="language" content="chinese">

<link href="css/index2.css" rel="stylesheet" type="text/css" />

</head>

<body>
<CENTER>

<table width="760" border="0" cellpadding="0" cellspacing="0">
  <tr><FORM name="login" action="http://bbs.chinaunix.net/logging.php?action=login"  method=post>
        <TD nowrap width="*" align="left">
        <script language="javascript" src="http://bbs.chinaunix.net/loginbox.php"></script>
        </TD>
</form>
  <FORM name=search action=http://s.chinaunix.net/bbs.php method=get>
    <TD vAlign=center align=right height=23 nowrap width="304"><a href=http://www.chinaunix.net/hot.shtml style="color: green; text-
decoration: none" target=_blank>今日推荐</a> [<a href=http://bbs3.chinaunix.net title="如果您觉得访问慢,欢迎访问我们的镜像站:http:
//bbs3.chinaunix.net" target=_blank><font color=red>论坛境像</font></a>]
          <INPUT maxLength=50 size=10 name=q>
<input type="hidden" name="title" value="fulltext">
<input type="hidden" name="st" value="title">
<input type="hidden" name="bbs" value="1">
<input type="hidden" name="forums" value="all">           
                  <INPUT name="submit" type=submit style="width:56px;height:17px;border:0;background:url('http://www.chinaunix.net/i
mages_new/search.gif');line-height:22px;cursor:hand;" value="">
    </TD>
  </FORM>
  </TR>
  </tr>
  <tr>
    <td height="1" colspan="2" bgcolor="#CCCCCC">
        <!-- 广告 begin -->
        <div width="760" height="80" id="cuad_35"></div><script language="javascript" src="http://count.chinaunix.net/js.php?id=35">
</script>
    <!-- 广告 end -->
        </td>
  </tr>
  <tr>
    <td height="60" colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="28%" height="60" style="vertical-align: middle"><img src="/images/culogo/indexlogo.gif" width="200" height="53" c
lass="td_m" /></td>
        <td class="td_m">

                <table class=nav width="100%" border="0" align="right" cellpadding="4" cellspacing="0">
--More--
作者: ynchnluiti    时间: 2008-12-26 15:26
原帖由 smallstar001 于 2008-12-26 15:16 发表
我有类似



很多,

我想下载它们的文本内容然后找我感兴趣的东西

我用
wget http://172.16.28.110/mantis/view.php?id=49

下载的怎么没有文本内容。该如何解决?

http://172.16.28.110/mantis/view.php?id=49 我这打不开
作者: 我是DBA    时间: 2008-12-26 15:27
对啊,你给的地址我这边打不开,所以换一个测试了一下。呵呵
作者: ynchnluiti    时间: 2008-12-26 15:29
原帖由 我是DBA 于 2008-12-26 15:27 发表
对啊,你给的地址我这边打不开,所以换一个测试了一下。呵呵

晕了,172.16是保留地址
作者: smallstar001    时间: 2008-12-26 15:31
恩 是我们公司内部的
作者: 我是DBA    时间: 2008-12-26 15:32
使用curl不可以吗、
作者: haimming    时间: 2008-12-26 15:32
怪不得我们看不到呢,呵呵
作者: ynchnluiti    时间: 2008-12-26 15:33
原帖由 smallstar001 于 2008-12-26 15:16 发表
我有类似



很多,

我想下载它们的文本内容然后找我感兴趣的东西

我用
wget http://172.16.28.110/mantis/view.php?id=49

下载的怎么没有文本内容。该如何解决?

wget -d -o logfile -O savefile URL

看看日志(logfile)
作者: smallstar001    时间: 2008-12-26 15:35
原帖由 haimming 于 2008-12-26 15:24 发表
我有两个脚本,看看对你有没帮助

第一个知道最后一页页数

#! /bin/bash
#done book from url
url="http://www.linuxsir.org/bbs/thread29701.html"
urlbase=${url%/*}
urlfile=${url##*/}
    wget  ...



w3m 是什么  我这好象没有这个命令,


这个好象也不行,哪个地址好象是能跳转的吧,

我的wget 会生成login_page.php?return=%2Fmantis%2Fview.php?id=49 文件名

但里面没有网页上显示的内容
作者: 我是DBA    时间: 2008-12-26 15:36
使用curl也不行么?
作者: smallstar001    时间: 2008-12-26 15:38
原帖由 ynchnluiti 于 2008-12-26 15:33 发表

wget -d -o logfile -O savefile URL

看看日志(logfile)



还是没有内容,都是标签,网页上的文本内容没有
作者: haimming    时间: 2008-12-26 15:39
标题: 回复 #12 smallstar001 的帖子
w3m是 "a text based Web browser and pager"
我用来显示输出的,有时在emacs下用,要下载安装的
作者: smallstar001    时间: 2008-12-26 15:40
原帖由 我是DBA 于 2008-12-26 15:36 发表
使用curl也不行么?



不行, 没反应,本地文件是空的

[root@CCOSS_484883689 mantis]# curl http://172.16.28.110/mantis/view.php?id=49 > a
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[root@CCOSS_484883689 mantis]# cat a
[root@CCOSS_484883689 mantis]#

作者: ynchnluiti    时间: 2008-12-26 15:41
原帖由 smallstar001 于 2008-12-26 15:38 发表



还是没有内容,都是标签,网页上的文本内容没有

savefile里都是标签?网页内容是不是由javascript生成的文本
作者: haimming    时间: 2008-12-26 15:44
login_page.php?return=%2Fmantis%2Fview.php?id=49

是不是要用户登录才能见内容的?
作者: 我是DBA    时间: 2008-12-26 15:45

这个比较难,没办法测试呢
作者: smallstar001    时间: 2008-12-26 15:48
原帖由 ynchnluiti 于 2008-12-26 15:41 发表

savefile里都是标签?网页内容是不是由javascript生成的文本


不知道呢,从源代码里能看见文本,但是一个个的找太麻烦了
作者: smallstar001    时间: 2008-12-26 15:51
原帖由 haimming 于 2008-12-26 15:44 发表
login_page.php?return=%2Fmantis%2Fview.php?id=49

是不是要用户登录才能见内容的?


恩,是阿,我注消了之后 直接看看不见
作者: 我是DBA    时间: 2008-12-26 15:53

难道要抓包,传session
作者: ynchnluiti    时间: 2008-12-26 15:53
原帖由 smallstar001 于 2008-12-26 15:48 发表


不知道呢,从源代码里能看见文本,但是一个个的找太麻烦了

是不是需要登录的问题?

如果是javascript, 搜搜document.write之类的。 看看文本是不是在参数里面。document.write("...")
作者: smallstar001    时间: 2008-12-26 15:54
原帖由 ynchnluiti 于 2008-12-26 15:53 发表

是不是需要登录的问题?

如果是javascript, 搜搜document.write之类的。 看看文本是不是在参数里面。document.write("...")



就是需要登陆才看的见
作者: smallstar001    时间: 2008-12-26 15:55
其事我就想得到那么多网页的源码
作者: ynchnluiti    时间: 2008-12-26 15:56
原帖由 smallstar001 于 2008-12-26 15:51 发表


恩,是阿,我注消了之后 直接看看不见

没登录就访问页面,可能会转到一个提示页面吧。你的意思是wget下载的提示页面内容也不对?
作者: ynchnluiti    时间: 2008-12-26 15:57
标题: 回复 #25 smallstar001 的帖子
php源码?
php源码没法用客户端工具通过web方式直接下载,下载的是php服务器处理过的。
作者: smallstar001    时间: 2008-12-26 15:59
原帖由 ynchnluiti 于 2008-12-26 15:57 发表
php源码?
php源码没法用客户端工具通过web方式直接下载,下载的是php服务器处理过的。



我说的源码就是跟浏览器差不多,查看源代码 ,

我就是想找文本内容而已
作者: 我是DBA    时间: 2008-12-26 16:00
curl 加一个post参数,传递用户跟密码后就可以看到了。
不过先要看一下登陆的标签
作者: smallstar001    时间: 2008-12-26 16:01
需要登陆的怎么办呢
作者: 我是DBA    时间: 2008-12-26 16:02
-u/--user <user:password>
              Specify  user and password to use when fetching. Read the MANUAL
              for detailed examples of how to use  this.  If  no  password  is
              specified, curl will ask for it interactively.

              You  can also use the --digest option to enable Digest authenti-
              cation when communicating with HTTP 1.1 servers.

              If this option is used several times, the last one will be used.
作者: ynchnluiti    时间: 2008-12-26 16:04
原帖由 smallstar001 于 2008-12-26 15:59 发表



我说的源码就是跟浏览器差不多,查看源代码 ,

我就是想找文本内容而已

我想也是。
那就需要先登录了。
wget有--post-data, 还有cookie相关的参数
                   # Log in to the server.  This can be done only once.
                   wget --save-cookies cookies.txt \
                        --post-data 'user=foo&password=bar' \
                        http://server.com/auth.php

                   # Now grab the page or pages we care about.
                   wget --load-cookies cookies.txt \
                        -p http://server.com/interesting/article

作者: smallstar001    时间: 2008-12-26 16:04
原帖由 我是DBA 于 2008-12-26 16:00 发表
curl 加一个post参数,传递用户跟密码后就可以看到了。
不过先要看一下登陆的标签


举个例子吧
作者: 我是DBA    时间: 2008-12-26 16:07
http://www.54haidao.com/web/article.php?articleid=113
curl 使用

http://www.chinaz.com/Program/PHP/0Q5354012008.html
作者: smallstar001    时间: 2008-12-26 16:14
我是想找个bug, 这个bug记录到那么多连接的一个里面了

我不能一个个去找吧,我要找页面文本,然后找关键字
作者: 我是DBA    时间: 2008-12-26 16:20
没空帮你研究,用curl应该可以的,我们开发有用curl有用来抓网页。
作者: smallstar001    时间: 2008-12-26 16:22
原帖由 ynchnluiti 于 2008-12-26 16:04 发表

我想也是。
那就需要先登录了。
wget有--post-data, 还有cookie相关的参数


这个是登陆页面  http://172.16.28.110/mantis/login_page.php

这个页面的代码
  1. <table class="width50" cellspacing="1">
  2. <tr>
  3.         <td class="form-title">
  4.                 登录        </td>
  5.         <td class="right">
  6.                 </td>
  7. </tr>
  8. <tr class="row-1">
  9.         <td class="category" width="25%">
  10.                 帐号        </td>
  11.         <td width="75%">
  12.                 <input type="text" name="username" size="32" maxlength="32" />
  13.         </td>
  14. </tr>
  15. <tr class="row-2">
  16.         <td class="category">
  17.                 密码        </td>
  18.         <td>
  19.                 <input type="password" name="password" size="16" maxlength="32" />
  20.         </td>
  21. </tr>
  22. <tr class="row-1">
  23.         <td class="category">
  24.                 记住此次登录        </td>
  25.         <td>
  26.                 <input type="checkbox" name="perm_login" />
  27.         </td>
  28. </tr>
  29. <tr>
  30.         <td class="center" colspan="2">
  31.                 <input type="submit" class="button" value="登录" />
  32.         </td>
  33. </tr>
  34. </table
复制代码


该怎么用wget登陆保存cookie,然后load cookie去下载其它网页的内容??
作者: smallstar001    时间: 2008-12-26 16:43
原帖由 我是DBA 于 2008-12-26 16:30 发表
curl -d "username=用户名&password=密码&button=登录" http://172.16.28.110/mantis/login_page.php
用这个试试:)



我要下载的是其它的网页  curl会保存cookie么?
作者: smallstar001    时间: 2008-12-26 16:50
算了 ,我在研究研究 andy分多  我就散给DBA算了
作者: ynchnluiti    时间: 2008-12-26 17:22
我用cu测试可以。红色是登录按钮的名字<.. type="submit" name="loginsubmit" ..>
wget -d -o log --keep-session-cookies cookie.txt --post-data "username=用户名&password=密码&loginsubmit='true'"  'http://bbs.chinaunix.net/logging.php?action=login&'

wget --load-cookies cookie.txt -p http://bbs.chinaunix.net/index.php -o log.2

作者: smallstar001    时间: 2008-12-26 17:25
原帖由 ynchnluiti 于 2008-12-26 17:22 发表
我用cu测试可以。红色是登录按钮的名字


太谢谢了, 还没测试,你真是好人
作者: ynchnluiti    时间: 2008-12-26 17:26
用curl也可以。
-d或者-F
  1. curl -c curl_cookie -F username=用户 -F password=密码 -F loginsubmit="true" 'http://bbs.chinaunix.net/logging.php?action=login&' >out
复制代码

作者: ly5066113    时间: 2008-12-26 17:35
原帖由 smallstar001 于 2008-12-26 17:25 发表


太谢谢了, 还没测试,你真是好人


严重同意,andy 兄超级有耐心。
作者: qishking    时间: 2008-12-27 08:40
原帖由 ynchnluiti 于 2008-12-26 15:29 发表

晕了,172.16是保留地址

我这也打不开
作者: vincentdpan    时间: 2008-12-29 13:03
? ? 搞不定
作者: smallstar001    时间: 2008-12-29 15:32
原帖由 ynchnluiti 于 2008-12-26 17:22 发表
我用cu测试可以。红色是登录按钮的名字



测试了下,还是不行 ,好象没有 --keep-session-cookie这个选项

我的需求是要先登陆login页面,然后去下载其它页面,

而且那个登陆按钮也没有name,看我发的那个登陆页面代码
作者: haimming    时间: 2008-12-29 15:37
标题: 回复 #47 smallstar001 的帖子
可以吧,登陆按钮是没有,不过,下载回来的页面是登录了的
作者: ynchnluiti    时间: 2008-12-29 15:38
原帖由 smallstar001 于 2008-12-29 15:32 发表



测试了下,还是不行 ,好象没有 --keep-session-cookie这个选项

我的需求是要先登陆login页面,然后去下载其它页面,

而且那个登陆按钮也没有name,看我发的那个登陆页面代码

我没试用button=xx代替可不可以,不过只发username=xxx&password=xxx,cu登录不成功。

--keep-session-cookies
我用的是GNU Wget 1.11.4。
作者: ynchnluiti    时间: 2008-12-29 15:40
标题: 回复 #48 haimming 的帖子
你试了只发username,passwod可以登录吗?
那可能我看错了。
作者: smallstar001    时间: 2008-12-29 15:46
原帖由 ynchnluiti 于 2008-12-29 15:38 发表

我没试用button=xx代替可不可以,不过只发username=xxx&password=xxx,cu登录不成功。

--keep-session-cookies
我用的是GNU Wget 1.11.4。

get --version
GNU Wget 1.9+cvs-stable (Red Hat modified)

版权所有 (C) 2003 Free Software Foundation, Inc.

好老的版本


只能用--save-cookies
作者: ynchnluiti    时间: 2008-12-29 15:58
原帖由 smallstar001 于 2008-12-29 15:46 发表

get --version
GNU Wget 1.9+cvs-stable (Red Hat modified)

版权所有 (C) 2003 Free Software Foundation, Inc.

好老的版本


只能用--save-cookies

save-cookies不行?那你man wget搜搜有没有session字样。

不行的话只能换版本或换工具了
作者: haomai    时间: 2008-12-30 19:54
真是不太清楚的了。
作者: dingning239    时间: 2009-01-01 18:57
save as。。。
作者: biglazybug    时间: 2009-01-01 20:18
标题: 回复 #54 dingning239 的帖子
啥意思?有吗
作者: lingonlei    时间: 2009-01-01 21:26
我很赞同!
作者: smallstar001    时间: 2009-01-04 15:58
原帖由 dingning239 于 2009-1-1 18:57 发表
save as。。。


save as ??

100个链接, 一个个save as?
作者: biglazybug    时间: 2009-01-04 15:59
标题: 回复 #57 smallstar001 的帖子
save as 怎么感觉想windows里用的那个......
作者: zhengyangas    时间: 2009-01-05 11:16
你们都用命令的啊?不用现成软件的工具的?好强
作者: haimming    时间: 2009-01-05 11:29
写脚本,用图形界面不好搞
作者: smallstar001    时间: 2009-01-05 11:36
原帖由 zhengyangas 于 2009-1-5 11:16 发表
你们都用命令的啊?不用现成软件的工具的?好强


wget这些命令本身就是工具, 你还要用什么软件工具呢?
作者: haimming    时间: 2009-01-05 11:57
通常人们只将图形界面,用鼠标点击的定义为软件
作者: 新警察    时间: 2009-03-20 08:07
回楼上,我第一次听到称呼GCC,GZIP,MAKE,VIM之类的为软件的时候,也是很困惑的,之后才慢慢适应了这个概念
好像windows 系统里的软件是看得到的,确实软乎乎的,如果用手捏一下,它就会变瘪了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2