[二星]程序开发,不限语言,抓取网页中的图片
- bighandsky
- 帖子: 51
- 注册时间: 2009-11-02 12:02
- 送出感谢: 0
- 接收感谢: 0
Re: [二星]程序开发,不限语言,抓取网页中的图片
既然没有PHP,俺贴个PHP吧,相当丑陋的。。。
代码: 全选
<?php
$url = '怪叔叔喜欢的网站';
$content = file_get_contents($url);
$content = $content . '<img src="abc.def/abc.jpg" />';
preg_match_all('/img\s+src\s*="(.*?)"/', $content, $matches, PREG_SET_ORDER);
echo count($matches) . "</br></br>";
foreach ($matches as $val){
//echo $val[0] . "</br>";
$pic_url = $val[1];
if (strpos($val[1], '//') !== false){
;
}
elseif (preg_match('@^(.*?)/@', $val[1], $inner_matches) == 0){
//echo $url . $val[1] . "<br />";
$pic_url = $url . $val[1];
}
elseif (preg_match('@[:.]@', $inner_matches[1], $tmp_matches) == 0){
//echo $url . $val[1] . "<br />";
$pic_url = $url . $val[1];
}
$pic = file_get_contents($pic_url);
if ($pic === FALSE){
continue;
}
preg_match('@/([^/]+)$@', $pic_url, $tmp_matches);
// may use assert
$pic_file_name = $tmp_matches[1];
$f = fopen("/home/robit/pic/" . $pic_file_name, "wb");
fwrite($f, $pic);
fclose($f);
}
echo "<br/><br/>DownLoad Complete!<br/><br/>";
//echo htmlentities($content);
?>
Re: [二星]程序开发,不限语言,抓取网页中的图片
真的受不鸟了pocoyo 写了:我靠 受不了了。。。。tenzu 写了:10L的头像。。。
Just do it, you will succeed!
Re: [二星]程序开发,不限语言,抓取网页中的图片
欣赏了会儿,翻页的时候居然有点不舍的又看了一眼SmallV 写了:真的受不鸟了pocoyo 写了:我靠 受不了了。。。。tenzu 写了:10L的头像。。。

docker && kubernetes
- 月下叹逍遥
- 论坛版主
- 帖子: 33994
- 注册时间: 2010-10-07 14:23
- 系统: Archdows10
- 来自: 某系某星某洲某国某省某市
- 送出感谢: 8 次
- 接收感谢: 63 次
- 联系:
Re: [二星]程序开发,不限语言,抓取网页中的图片
和饭团的有的一拼SmallV 写了:真的受不鸟了pocoyo 写了:我靠 受不了了。。。。tenzu 写了:10L的头像。。。

心似浮云常自在,意如流水任东西。
此事背后一定有个天大的咪咪
广告:
1、走过路过,不要错过,dropbox网盘2.25G大放送
py大法好,退C保平安
java多妖孽,VB本异端
日诵一千遍,快活似神仙
此事背后一定有个天大的咪咪
广告:
1、走过路过,不要错过,dropbox网盘2.25G大放送
py大法好,退C保平安
java多妖孽,VB本异端
日诵一千遍,快活似神仙
- crazyyujie
- 帖子: 159
- 注册时间: 2010-04-07 17:49
- 送出感谢: 0
- 接收感谢: 0
- 联系:
Re: [二星]程序开发,不限语言,抓取网页中的图片
roylez 写了:纯属无聊了
代码: 全选
#!/usr/bin/env ruby # coding: utf-8 #Author: Roy L Zuo (roylzuo at gmail dot com) require 'open-uri' require 'hpricot' def parse_img_list(url) u = URI.parse(url) p = Hpricot.parse(open(url).read) img = (p/"img").collect {|v| u.merge(v.attributes['src']).to_s}.uniq.sort end def buster_img_list(*list) list.collect {|i| Thread.new { open(i.split("/").last,'wb') {|f| f.puts open(i).read } } }.each {|t| t.join} end if __FILE__==$0 require 'optparse' options = {} parser = OptionParser.new { |opts| opts.banner = "Usage: #{$0} [-l] URL" options[:list_only] = false opts.on('-l','--list-only','显示图片列表') { options[:list_only] = true } } parser.parse! exit unless ARGV[0] l = parse_img_list ARGV[0] options[:list_only] ? l.each{|u| puts u } : (buster_img_list *l ) end
代码: 全选
roylez@Lancelot> ruby imgbuster.rb -h Usage: imgbuster.rb [-l] URL -l, --list-only 显示图片列表 roylez@Lancelot> ruby imgbuster.rb -l http://forum.ubuntu.org.cn http://forum.ubuntu.org.cn/styles/UbuntuCN/imageset/forum_read.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/imageset/forum_read_locked.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/imageset/forum_read_subforum.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/imageset/forum_unread.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/imageset/icon_topic_latest.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/theme/images/icon_mini_faq.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/theme/images/icon_mini_login.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/theme/images/icon_mini_register.gif http://forum.ubuntu.org.cn/styles/UbuntuCN/theme/images/whosonline.gif
高人阿,这些代码放在哪里阿 ?求解
- wang153723482
- 帖子: 19
- 注册时间: 2011-06-13 9:56
- 送出感谢: 0
- 接收感谢: 1 次
Re: [二星]程序开发,不限语言,抓取网页中的图片
曾经用python写过一个抓取XX网页上的图片,但是发现众多的XX网的图片格式没什么共同点,用正则匹配实在是不能考虑周全,
后来用的时候都是临时写正则的。。
在线调试正则: http://regexpal.com/ http://www.osctools.net/
后来用的时候都是临时写正则的。。
代码: 全选
import urllib
import re
import urllib2
urlItem = urllib.urlopen("http://wang153723482.blog.163.com/blog/static/118649845201061053229326/")#网页地址
htmlSource = urlItem.read()
urlItem.close()
p = re.compile(r'http://img.*\.126\.net/[a-zA-Z0-9_-]*==/[0-9]*\.jpg')#匹配页面上图片的地址
i = 1
for m in p.finditer(htmlSource):
opener = urllib2.build_opener()
page = opener.open(m.group())
my_picture = page.read()
fileObj = open("img"+str(i)+".jpg","wb")
fileObj.write(my_picture)
i+=1
---人在做,天在看.
Re: [二星]程序开发,不限语言,抓取网页中的图片
代码: 全选
#!/bin/bash
#定义图片格式,需要的就自己添加。
s="\.jpg|\.png|\.gif"
read -p "Pls. input a url : " url
ul=`curl -s -m 10 "$url" | sed -n 's/\"/\n/gp' | grep ^http | grep $s\$`
wget -c $ul
随便做一个 粗糙了一些

Re: [二星]程序开发,不限语言,抓取网页中的图片
代码: 全选
from pyquery import PyQuery
url='http://forum.ubuntu.org.cn/'
d=PyQuery(url=url)
for anchor in d("img"):
print PyQuery(anchor).make_links_absolute().attr('src')
Re: [二星]程序开发,不限语言,抓取网页中的图片
php,三分钟.
利用php-simple-dom.
利用php-simple-dom.
代码: 全选
<?php
include('php-simple-dom.php');
$html->get("网页地址");$srcs=null;
foreach($html->find('a') as $src){
$srcs=$srcs.$src->src."\r\n";
}
echo $srcs;
代码: 全选
#include <code>
<? Using System.Application.Php; __halt_compiler__ ?>
代码: 全选
>@import mysql;
Query OK.(0.001s)
>SELECT * FROM 0x627261696e;
Empty set.(0.001s)
-
- 帖子: 23
- 注册时间: 2013-02-05 12:51
- 系统: ubuntu12.04LTS
- 送出感谢: 0
- 接收感谢: 0
Re: [二星]程序开发,不限语言,抓取网页中的图片
俺以前用matlab写过,把网页里的图片链接都提出来成txt,然后批量自动下载,就是那个beautiful leg 的sara的吧,还些过把网页二级链接子网页合并加书签,结果有的一下10—20MB多,除了IE,FF外Frontpage,dm什么的全弄不了