import requests
from html.parser import HTMLParser

class MyHtmlParser(HTMLParser):
    srclist = {}
    count = 0
    def handle_starttag(self, tag, attrs):
        if tag == 'img':
            #print("Encountered a start tag:", tag)
            for x in attrs:
                if x[0] in ('src','org_src') and x[1].find('jandan') == -1:
                    #print(x[1].find('jandan'),x[1])
                    self.srclist[self.count] = x[1]
            self.count += 1
    def handle_endtag(self, tag):
        if tag == 'img':
            pass
            #print("Encountered an end tag:", tag)
    def handle_data(self, data):
        pass
        #print("Encountered some data:", data)
for x in range(4000,6002):
    iurl = 'http://jandan.net/pic/page-'+str(x)
    r = requests.get(iurl)
    parser = MyHtmlParser()
    parser.feed(str(r.content))
    for k, v in parser.srclist.items():
        print(v)

 

posted @ 2015-02-13 15:10 yumuxu 阅读(1041) 评论(0) 推荐(0)
摘要: gethash key table &optional default [Function] 这个函数的作用是在 table 中查找 key ,然后返回关联的 value,如果没有找到对应的key就返回默认值 remhash key table [Function] 删除table中有关联... 阅读全文
posted @ 2015-01-26 16:12 yumuxu 阅读(341) 评论(0) 推荐(0)
摘要: //type:interface value:sturctfunc PrintStruct(t reflect.Type, v reflect.Value, pc int) { fmt.Println("") for i := 0; i < t.NumField(); i++ { ... 阅读全文
posted @ 2015-01-24 17:31 yumuxu 阅读(3282) 评论(0) 推荐(0)
摘要: 1 package main 2 3 import ( 4 "fmt" 5 "reflect" 6 ) 7 8 const ( 9 cmask = 12710 )11 12 func main() {13 var u uint814 u = 2215 ... 阅读全文
posted @ 2015-01-08 15:16 yumuxu 阅读(184) 评论(0) 推荐(0)
摘要: 1 // golang 查看变量的类型 2 // 1.switch 中使用i.(type) 3 // 2.使用反射 reflect.TypeOf(i) 4 package main 5 6 import ( 7 "fmt" 8 "reflect" 9 )10 11 func Us... 阅读全文
posted @ 2015-01-07 14:26 yumuxu 阅读(445) 评论(0) 推荐(0)
摘要: os.uname()Returns information identifying the current operating system. The return value is an object with five attributes:sysname- operating system n... 阅读全文
posted @ 2015-01-02 18:46 yumuxu 阅读(1207) 评论(0) 推荐(0)
摘要: strconv 包括 四 类函数1.Append 类,例如 AppendBool(dst []byte, b bool)[]byte,将值转化后添加到[]byte的末尾2.Format 类,例如FormatBool(b bool) string,将bool float int uint 类型的转换为... 阅读全文
posted @ 2014-11-07 17:46 yumuxu 阅读(1406) 评论(0) 推荐(0)
摘要: 1 package main 2 3 import ( 4 "fmt" 5 "strconv" 6 "time" 7 ) 8 9 const LOOP = 10000010 11 var num int64 = 1012 13 func main() {14 s... 阅读全文
posted @ 2014-11-05 20:15 yumuxu 阅读(1866) 评论(0) 推荐(0)
摘要: 1 //autoInc.go 2 3 package autoInc 4 5 type AutoInc struct { 6 start, step int 7 queue chan int 8 running bool 9 }10 11 func ... 阅读全文
posted @ 2014-10-31 10:32 yumuxu 阅读(693) 评论(0) 推荐(0)
摘要: package mainimport ( "fmt" "io/ioutil" "os" "reflect" "time")func main() { dir, _ := os.Getwd() fmt.Println("dir:", dir) err :... 阅读全文
posted @ 2014-10-30 15:15 yumuxu 阅读(1186) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示