国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python使用urllib2模塊抓取HTML頁面資源的實例分享

2019-11-25 16:48:52
字體:
來源:轉載
供稿:網友

先把要抓取的網絡地址列在單獨的list文件中

//m.survivalescaperooms.com/article/83440.html//m.survivalescaperooms.com/article/83437.html//m.survivalescaperooms.com/article/83430.html//m.survivalescaperooms.com/article/83449.html

然后我們來看程序操作,代碼如下:

#!/usr/bin/pythonimport osimport sysimport urllib2import redef Cdown_data(fileurl, fpath, dpath): if not os.path.exists(dpath):  os.makedirs(dpath) try:  getfile = urllib2.urlopen(fileurl)   data = getfile.read()  f = open(fpath, 'w')  f.write(data)  f.close() except: print with open('u1.list') as lines: for line in lines:  URI = line.strip()  if '?' and '%' in URI:   continue elif URI.count('/') == 2:   continue  elif URI.count('/') > 2:   #print URI,URI.count('/')  try:    dirpath = URI.rpartition('/')[0].split('//')[1]    #filepath = URI.split('//')[1].split('/')[1]    filepath = URI.split('//')[1]   if filepath:     print URI,filepath,dirpath     Cdown_data(URI, filepath, dirpath)   except:    print URI,'error'

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永泰县| 江安县| 芷江| 淳安县| 大关县| 嵊州市| 天峨县| 微山县| 长岭县| 德惠市| 资中县| 巴塘县| 海林市| 焉耆| 平潭县| 务川| 汤阴县| 来宾市| 恩平市| 藁城市| 横峰县| 永新县| 萨迦县| 临夏市| 昭平县| 壶关县| 辽源市| 宜兴市| 呼玛县| 双柏县| 滦南县| 伊通| 舟山市| 神木县| 寻乌县| 鲁甸县| 德昌县| 陆河县| 永州市| 米林县| 阜阳市|