Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
venusing1998 committed Jan 4, 2019
1 parent c3ca59e commit 923aa22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions json_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ def main():
# print('Enter the keyowrd: ', end='')
# kw = input()
kw = 'correct'
start = time.time()
start_time = time.time()
counter = 0
for i in range(0, 3600, 24):
spider = Spider(kw, start=i)
for start in range(0, 3600, 24):
spider = Spider(kw, start=start)
response = spider.get_html()
items = spider.test(response)
if items:
spider.write_into_file(response)
print(
'Downloading: {0}.json It costs {1}s'.format(
str(i // 24 + 1), str(time.time() - start)),)
str(start // 24 + 1), str(time.time() - start_time)),)
counter += 1
else:
break
print('Get {0}. It costs {1}s'.format(counter, str(time.time() - start)))
print('Get {0}. It costs {1}s'.format(
counter, str(time.time() - start_time)))


if __name__ == '__main__':
Expand Down
16 changes: 8 additions & 8 deletions spider_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def test(self, response):
items['path'] = path
yield items

def get_html_2(self, item):
def get_html_2(self, items):
try:
url = item.get('path')
url = items.get('path')
headers = {
'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
Expand Down Expand Up @@ -117,26 +117,26 @@ def main():
# print('Enter the keyowrd: ', end='')
# kw = input()
kw = 'correct'
start = time.time()
start_time = time.time()
counter = 0
for i in range(0, 3600, 24):
spider = Spider(kw, start=i)
for start in range(0, 3600, 24):
spider = Spider(kw, start=start)
response = spider.get_html()
items = spider.test(response)
if items:
for item in items:
format, response = spider.get_html_2(item)
if format == 'gif':
print('Downloading: {0} It costs {1}s.'.format(
item['path'][:-5], time.time() - start))
item['path'][:-5], time.time() - start_time))
else:
print('Downloading: {0} It costs {1}s.'.format(
item['path'], time.time() - start))
item['path'], time.time() - start_time))
counter += 1
spider.write_into_file(format, response)
else:
break
print('Get {0}. It costs {1}s'.format(counter, str(time.time() - start)))
print('Get {0}. It costs {1}s'.format(counter, str(time.time() - start_time)))


if __name__ == '__main__':
Expand Down

0 comments on commit 923aa22

Please sign in to comment.