使用终端下载所有 ctrl alt del 网络漫画

发布于 2024-08-31 19:23:26 字数 441 浏览 1 评论 0原文

我尝试使用以下命令来下载 ctrl alt del 漫画。

$ for filename in $(seq 20021023 20100503); do wget http://www.ctrlaltdel-online.com/comics/"$filename".jpg; done

我收到以下错误代码,bash:意外标记“do”附近的语法错误

我也尝试使用 cURL,使用此命令,

curl http://ctrlaltdel-online.com/comics[20021023..20100503].jpg

我收到以下错误代码,curl:(3 ) [globbing] 错误: pos 37 之后的范围规范错误

出了什么问题,如何修复它?

I've tried using the following commands to download the ctrl alt del comics.

$ for filename in $(seq 20021023 20100503); do wget http://www.ctrlaltdel-online.com/comics/"$filename".jpg; done

I get the following error code, bash: syntax error near unexpected token 'do'

I've also tried using cURL, using this command,

curl http://ctrlaltdel-online.com/comics[20021023..20100503].jpg

I get the following error code, curl: (3) [globbing] error: bad range specification after pos 37

What's wrong, and how can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平安喜乐 2024-09-07 19:23:26

正如 MSW 指出的那样,抓取网站可能是非法的、不道德的、令作者恼怒的,也可能是完全正常的。请以负责任的方式使用您的脚本编写能力,并以公益为目的 (tm)。寻求许可肯定是一件好事。

请注意,ctrlaltdel-online.com Web 服务器似乎使用正常的 wget 用户代理字符串返回 HTTP 403 禁止 wget。模仿 Firefox 风格的东西似乎绕过了这一点(尽管我打赌他们只是明确拒绝 wget,这表明他们很可能禁止这种类型的访问)。

USERAGENT='Mozilla/5.0 Firefox/3.6.3'
for DAYS in $(seq 365)
do
    NEXT=`date -d "${DAYS} days ago" +%Y%m%d`
    wget -U "${USERAGENT}" "http://www.cad-comic.com/comics/cad/${NEXT}.jpg"
done

用更大的数字替换 365 可以追溯到一年多之前。 wget 输出可能很烦人,因此您可以传递 -q 使其安静。

As msw pointed out, crawling a site could be either illegal, unethical, irritating to the author, or perfectly fine. Please use your scripting powers responsibly and for Good (tm). Asking permission would certainly be a nice thing to do.

Note that the ctrlaltdel-online.com web server seems to return HTTP 403 forbidden to wget with the normal wget User-Agent string. Emulating something Firefox-ish seems to bypass that (although I bet they are just explicitly denying wget, which indicates they most likely forbid this type of access).

USERAGENT='Mozilla/5.0 Firefox/3.6.3'
for DAYS in $(seq 365)
do
    NEXT=`date -d "${DAYS} days ago" +%Y%m%d`
    wget -U "${USERAGENT}" "http://www.cad-comic.com/comics/cad/${NEXT}.jpg"
done

Replace 365 with a larger number to go back more than a year. The wget output might be annoying, so you can pass it -q to make it quiet.

[浮城] 2024-09-07 19:23:26

我正在写同样的脚本。这里是。

import sys
import re
import urllib
import os
import ctypes
from urllib import FancyURLopener

class MyOpener(FancyURLopener):
    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it;rv:1.8.1.11)Gecko/20071127 Firefox/2.0.0.11'


def getlinks(add,m,opener):
    ufile=opener.open(add)
    html=ufile.read()
    dates=re.findall('href="/cad/(\d+)">',html)
    links=[]
    for date in dates:
            if date[4:6]==m:
            links.append('http://www.cad-comic.com/cad/'+date)
    links.reverse()
    print 'Total {} comics found.'.format(len(links))
    #print len(links)
    return links

def getstriplink(link,opener):
    ufile=opener.open(link)
    html=ufile.read()
    url=re.search('img src="(.+)" alt="(.+)" title=',html)
    date=link[-8:]
    return(url.group(1),url.group(2),date)



def main():
    y=raw_input('Enter year 2002 - current(yyyy) ')
    m=raw_input('Enter month(only months 12,11 and 10 for 2002)(mm) ')
    add='http://www.cad-comic.com/cad/archive/'+y
    opener=MyOpener()
    links=getlinks(add,m,opener)
    f=open('/media/aux1/pythonary/cad'+str(y)+str(m)+'.html','w')
    print 'downloading'
    for link in links:
        url=getstriplink(link,opener)
        #date=url[0][-8:]
        date=url[2]
        opener.retrieve(url[0],'/media/aux1/pythonary/getcad_files/strip'+date)
        sys.stdout.flush()
        print'.',
        f.write('<h2>'+url[1]+' '+date+'</h2>'+'<p><img src="getcad_files/strip'+date+'"/></p>')

    f.close()




if __name__ == '__main__':
  main()

i was writing the same script. Here it is.

import sys
import re
import urllib
import os
import ctypes
from urllib import FancyURLopener

class MyOpener(FancyURLopener):
    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it;rv:1.8.1.11)Gecko/20071127 Firefox/2.0.0.11'


def getlinks(add,m,opener):
    ufile=opener.open(add)
    html=ufile.read()
    dates=re.findall('href="/cad/(\d+)">',html)
    links=[]
    for date in dates:
            if date[4:6]==m:
            links.append('http://www.cad-comic.com/cad/'+date)
    links.reverse()
    print 'Total {} comics found.'.format(len(links))
    #print len(links)
    return links

def getstriplink(link,opener):
    ufile=opener.open(link)
    html=ufile.read()
    url=re.search('img src="(.+)" alt="(.+)" title=',html)
    date=link[-8:]
    return(url.group(1),url.group(2),date)



def main():
    y=raw_input('Enter year 2002 - current(yyyy) ')
    m=raw_input('Enter month(only months 12,11 and 10 for 2002)(mm) ')
    add='http://www.cad-comic.com/cad/archive/'+y
    opener=MyOpener()
    links=getlinks(add,m,opener)
    f=open('/media/aux1/pythonary/cad'+str(y)+str(m)+'.html','w')
    print 'downloading'
    for link in links:
        url=getstriplink(link,opener)
        #date=url[0][-8:]
        date=url[2]
        opener.retrieve(url[0],'/media/aux1/pythonary/getcad_files/strip'+date)
        sys.stdout.flush()
        print'.',
        f.write('<h2>'+url[1]+' '+date+'</h2>'+'<p><img src="getcad_files/strip'+date+'"/></p>')

    f.close()




if __name__ == '__main__':
  main()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文