-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrawler.py
More file actions
42 lines (36 loc) · 1.06 KB
/
Copy pathCrawler.py
File metadata and controls
42 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import shutil
from icrawler.builtin import BingImageCrawler
class Crawler:
def __init__(self, keyword, num, loc):
self.keyword = keyword
self.num = num
self.loc = loc
def work(self,keyword, num, loc):
print("Start crawling imgs...")
bing_crawler = BingImageCrawler(
feeder_threads=1,
parser_threads=2,
downloader_threads=4,
storage={'root_dir': loc}
).crawl(
keyword=keyword,
max_num=num,
)
print("Crawling complete. Pos: {}".format(loc))
return
def run(self):
self.work(self.keyword, self.num, self.loc)
def main():
keyword=input('请输入要爬取的关键词:')
num=input('请输入要爬取的图片数量:')
imgpath = 'imgs'
loc = os.path.join(imgpath, 'test',keyword)
if os.path.exists(loc):
shutil.rmtree(loc)
os.makedirs(loc, exist_ok=True)
crawler = Crawler(keyword, int(num), loc)
crawler.run()
print("Accepted.")
if __name__ == '__main__':
main()