批量查询网页状态码以及标题

做SEO以及SEM的时候经常会要用到查询网页的标题以及状态码,这篇文章使用2种方法批量查询网页标题与状态码。并快速批量导出数据

使用爱站SEO工具

操作如上图,直接通过文件导入然后可以批量查询网页的状态码,但是不能够批量查询网页标题

domain2ip

1. github完整的python包。下载地址https://github.com/telllpu/domain2ip

2. 修改下载文件domain2ip.py 第169行 修改导入文件目录

3.python 运行脚本

4.如果python 程序不能运行 可通过下列命令行进行安装

pip install ipwhois

poython 批量查询ip脚本

脚本要求:python 2.7版本,如果缺乏部分插件可以直接pip进行安装

修改下文中:/mnt/d/web.txt 为链接地址

/mnt/d/jieguo.txt 为保存地址

#coding=utf-8
import urllib,time
import StringIO
import pycurl

def get_http_status(url):
    html = StringIO.StringIO()
    c = pycurl.Curl()
    myurl=url
    c.setopt(pycurl.URL, myurl)
    c.setopt(pycurl.WRITEFUNCTION, html.write)
    c.setopt(pycurl.FOLLOWLOCATION, 1)
    c.setopt(pycurl.MAXREDIRS, 5)
    c.setopt(pycurl.CONNECTTIMEOUT, 60)
    c.setopt(pycurl.TIMEOUT, 300)
    c.setopt(c.HEADER, True)
    c.setopt(pycurl.USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)")
    ret = c.perform()
    ret = html.getvalue()
    if "200" in ret:
        print url,c.getinfo(c.HTTP_CODE)
        return 1
    elif "404" in ret:
        print url,c.getinfo(c.HTTP_CODE)
        f = open(' /mnt/d/web.txt ','a')
        f.write(url+'\n')
        f.close()
        return 0

if __name__=="__main__":
    urls=open(' /mnt/d/jieguo.txt','r').readlines()
    oknum=0
    lostnum=0
    for url in urls:
        if get_http_status(url.strip()):
            oknum+=1
        else:
            lostnum+=1

相关推荐

批量docx互转md

在项目中经常需要将docx和md文件互相转换 使用条件 可以上 Pandoc 官网 Pandoc 查询其他支持 ...

常见的编码有那些

常见编码 ASCII码 这是美国在19世纪60年代的时候为了建立英文字符和二进制的关系时制定的编码规范,它能表 ...