标签: vi

  • Python 爬虫 抓取豆瓣小组图片 通过api提交入库到 Chevereto 图床

    Python 爬虫 抓取豆瓣小组图片 通过api提交入库到 Chevereto 图床

    最近没事弄了一个图床(http://788to.com),然后又比较喜欢豆瓣小组里的图片,所以就想从豆瓣小组抓取图片。老季只对php比较了解,但是php的多线程做爬虫的话还是比较弱的,所以就想到了用Python来做这件事情。

    前篇:Chevereto free版本 使用api 上传图片 图文教程

    注:老季是Python新手,如有不对的地方,希望大神指出。

    下面将python脚本开源:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    # 作者:老季
    # 网址:https://www.jiloc.com/43112.html
    #导入所需的库
    from bs4 import BeautifulSoup
    from urllib.parse import urlencode
    import urllib.request,socket,re,sys,os,json,time,threading,queue
    
    # 获取单页图片方法
    def getImage(url): 
        # 网址
        if url == '':
            print('URL NULL')
            sys.exit()
        print(url)
        print('--- Begin to Crawl Url ---')
        req = urllib.request.Request(url)
        res = urllib.request.urlopen(req)
        data = res.read()
        for link,t in set(re.findall(r'(https://img3.doubanio.com/view/group_topic/large/public/[^s]*?(jpg))', str(data))):
            if  link != '' :
                http_status = http_get(link)
                print( link + ' -> '+ http_status )
    #        print(link)
        print('--- End to Crawl Url ---')
    
    # 获取页面的url地址并使用getImage方法抓取图片
    def getUrlList(url):
        data=urllib.request.urlopen(url).read()  
        soup = BeautifulSoup(data, "html.parser")
        tdList = soup.find_all("td",class_='title')        
        for i in tdList:
            title = i.a.get("title")
            if len(i.contents) > 1:
                i_href = i.a.get('href')
                getImage(i_href)
    
    # 模拟浏览器提交数据
    def http_get(url):
        submit_url = 'http://788to.com/api/1/upload/?key='+urllib.parse.quote_plus('API值')+'&source='+urllib.parse.quote_plus(url)
    #    print(submit_url)
        req = urllib.request.Request(submit_url)
        try:
            res = urllib.request.urlopen(req)
        except urllib.error.HTTPError as e:
            print(e.read())      
            sys.exit()
        # .decode('ascii') : 将byte类型转化为字符串格式
    #    return res.read().decode('ascii')
        data = json.loads(res.read().decode())
        return str(data['status_code'])
    
    #getUrlList('https://www.douban.com/group/meituikong/discussion?start=400')
    print('群组起始地址示例:https://www.douban.com/group/meituikong/discussion?start=')
    theUrl = str(input("请输入豆瓣首页地址:"))
    theEnd = int(input('请输入最后一页的start数字值:'))
    class jdThread(threading.Thread):
        def __init__(self,index,queue):
            threading.Thread.__init__(self)
            self.index = index
            self.queue = queue
     
        def run(self):
            while True:
                time.sleep(1)
                item = self.queue.get()
                if item is None:
                    break
    #            print("序号:",self.index,"任务",item,"完成")
                getUrlList(theUrl+str(item*25))
                time.sleep(1)
                self.queue.task_done()  #task_done方法使得未完成的任务数量-1
                if q.empty(): return
    
    q = queue.Queue(0)
    '''
    初始化函数接受一个数字来作为该队列的容量,如果传递的是
    一个小于等于0的数,那么默认会认为该队列的容量是无限的.
    '''
    for i in range(2):
        jdThread(i,q).start()#两个线程同时完成任务
    for i in range( int( theEnd/25) ):
        q.put(i)#put方法使得未完成的任务数量+1
    

     

  • Git 设置远程仓库 初始化push 图文教程

    Git 设置远程仓库 初始化push 图文教程

    Git – setting up a remote repository and doing an initial push

    There is a great deal of documentation and many posts on Git out there, so this is more of a note to self as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.

    这里记录一下push远程仓库所需要的步骤:

    So, firstly setup the remote repository:

    首先设置远程仓库:

    ssh git@example.com
    mkdir my_project.git
    cd my_project.git
    git init --bare
    git update-server-info # If planning to serve via HTTP
    exit

    On local machine:

    本地机器:

    cd my_project
    git init
    git add *
    git commit -m "My initial commit message"
    git remote add origin git@example.com:my_project.git
    git push -u origin master

    Done!

    完成!

    Team members can now clone and track the remote repository using the following:

    其他团队成员直接克隆远程仓库内容即可:

    git clone git@example.com:my_project.git
    cd my_project

    Bonus

    To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile (I have my current directory displayed in cyan):

    function git-branch-name {
      git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
    }
    function git-branch-prompt {
      local branch=`git-branch-name`
      if [ $branch ]; then printf " [%s]" $branch; fi
    }
    PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "
  • CentOS配置Nginx官方Yum源 进行安装 图文教程

    CentOS配置Nginx官方Yum源 进行安装 图文教程

    nginx

    这不是前两天子凡搞了个小鸟云的免费云主机,正准备搭建个WEB环境来玩玩,结果直接使用“yum -y install nginx”安装才发现默认yum仓库没有nginx,所以就无法直接安装nginx了,所以今天就和子凡一起来简单的配置一下吧!

    由于yum源中没有我们想要的nginx,那么我们就需要创建一个“/etc/yum.repos.d/nginx.repo”的文件,其实就是新增一个yum源。

    vi /etc/yum.repos.d/nginx.repo

    然后将下面的内容复制进去:

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1

    然后保存“/etc/yum.repos.d/nginx.repo”文件后,我们就使用yum命令查询一下我们的nginx的yum源配置好了没有。

    # yum list |grep nginx
    nginx.x86_64 1:1.10.1-1.el7.ngx nginx
    nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx
    nginx-debuginfo.x86_64 1:1.10.1-1.el7.ngx nginx
    nginx-module-geoip.x86_64 1:1.10.1-1.el7.ngx nginx
    nginx-module-image-filter.x86_64 1:1.10.1-1.el7.ngx nginx
    nginx-module-njs.x86_64 1:1.10.1.0.0.20160414.1c50334fbea6-1.el7.ngx
    nginx
    nginx-module-perl.x86_64 1:1.10.1-1.el7.ngx nginx
    nginx-module-xslt.x86_64 1:1.10.1-1.el7.ngx nginx
    nginx-nr-agent.noarch 2.0.0-9.el7.ngx nginx
    pcp-pmda-nginx.x86_64 3.10.6-2.el7 base

    如果执行命令是这样的显示效果,那么我们的nginx的yum源就配置成功啦!

    然后要安装我们的nginx就直接执行:

    yum -y install nginx

    如果操作正确到这里nginx环境就已经安装OK了。

    当然你还可以使用命令查一下究竟是否安装完成。

    # rpm -q nginx
    nginx-1.10.1-1.el7.ngx.x86_64

    不解释,已经成功了,并且是nginx官方的最新版本。

WeChat