add code to handle the situation that only using js to redirect

This commit is contained in:
5a43 2016-06-26 14:46:29 +08:00
parent 20acf915c0
commit b850641e85

View File

@ -142,8 +142,16 @@ def _search(dork):
try: try:
r = requests.get(baidu_link, timeout=10) r = requests.get(baidu_link, timeout=10)
if r and r.status_code == 200: if r and r.status_code == 200:
logger.info(r.url) # baidu will just use Javascript to redirect the page rather than responding a 302 HTTP code.
retVal.append(r.url) if r.history:
logger.info(r.url)
retVal.append(r.url)
else:
m = re.search('<script>window\.location\.replace\("(?P<url>.+?)"\)', r.content, re.I)
if m:
url = m.group('url')
logger.info(url)
retVal.append(url)
except Exception, e: except Exception, e:
logger.debug(e.message) logger.debug(e.message)
retVal = _remove_duplicate(retVal) retVal = _remove_duplicate(retVal)