forked from nladuo/captcha-break
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move downloader.py
os.remove
to clean.py etc.
- Loading branch information
Showing
2 changed files
with
34 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
import os | ||
for fn in os.listdir("./captchas/"): | ||
if os.path.splitext(fn)[1] == '.gif': | ||
os.remove("./captchas/"+fn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
# coding:utf-8 | ||
import requests | ||
import uuid | ||
from PIL import Image | ||
import os | ||
from bs4 import BeautifulSoup | ||
|
||
url = "http://login.weibo.cn/login/" | ||
for i in range(2000): | ||
try: | ||
resp = requests.get(url) | ||
bsObj = BeautifulSoup(resp.content, "lxml") | ||
image_url = str(bsObj.img['src']) | ||
resp = requests.get(image_url) | ||
filename = str(uuid.uuid4()) + ".gif" | ||
with open("./captchas/" + filename, 'wb') as f: | ||
for chunk in resp.iter_content(chunk_size=1024): | ||
if chunk: # filter out keep-alive new chunks | ||
f.write(chunk) | ||
f.flush() | ||
f.close() | ||
im = Image.open("./captchas/" + filename) | ||
try: | ||
im = Image.open("./captchas/" + filename) | ||
im.save("./captchas/" + filename.split('.gif')[0] + ".png") | ||
except Exception, ex: | ||
print Exception, ":", ex | ||
os.remove("./captchas/" + filename) | ||
print filename | ||
except Exception, ex: | ||
print Exception, ":", ex | ||
# coding:utf-8 | ||
import requests | ||
import uuid | ||
from PIL import Image | ||
import os | ||
from bs4 import BeautifulSoup | ||
|
||
url = "http://login.weibo.cn/login/" | ||
for i in range(2000): | ||
try: | ||
resp = requests.get(url) | ||
bsObj = BeautifulSoup(resp.content, "html.parser") | ||
image_url = str(bsObj.img['src']) | ||
#print(image_url) | ||
resp = requests.get(image_url) | ||
filename = str(uuid.uuid4()) + ".gif" | ||
with open("./captchas/" + filename, 'wb') as f: | ||
f.write(resp.content) | ||
|
||
try: | ||
with Image.open("./captchas/" + filename) as im: | ||
im.save("./captchas/" + filename.split('.gif')[0] + ".png") | ||
|
||
except Exception as ex: | ||
print(Exception, ":", ex) | ||
#os.remove("./captchas/" + filename) | ||
print(filename) | ||
except Exception as ex: | ||
print(Exception, ":", ex) |