import urllib.request
import re
import time
import random
class GetHtml(object):
def __init__(self, URL, HEAD):
self.url = URL
self.head = HEAD
def get_index(self):
self.request = urllib.request.Request(self.url)
self.request.add_header("user-agent", self.head)
self.response = urllib.request.urlopen(self.request)
return self.response.read()
def get_imgList(self):
self.stringimglist = []
self.imglist = re.findall(b"/fx53vd_files/\w{40}.jpg", self.get_index())
for i in self.imglist:
self.stringimglist.append(self.url + str(i, encoding="utf8"))
return self.stringimglist
def download_img(self):
# num = time.time()
for self.url in self.get_imgList():
time.sleep(0.01)
# num += random.randint(0,9):
with open("C:\\Users\\Administrator\\Desktop\\pachong\\" + str(time.time()) + ".jpg", "wb") as f:
f.write(self.get_index())
html = GetHtml("http://10.1.1.3",
"Mozilla/9999999999.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36")
html.download_img()
Python爬虫
最新推荐文章于 2020-08-19 23:39:23 发布