| 238 | storeResultsToFile(kb.targets) |
| 239 | |
| 240 | def storeResultsToFile(results): |
| 241 | if not results: |
| 242 | return |
| 243 | |
| 244 | if kb.storeCrawlingChoice is None: |
| 245 | message = "do you want to store crawling results to a temporary file " |
| 246 | message += "for eventual further processing with other tools [y/N] " |
| 247 | |
| 248 | kb.storeCrawlingChoice = readInput(message, default='N', boolean=True) |
| 249 | |
| 250 | if kb.storeCrawlingChoice: |
| 251 | handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.CRAWLER, suffix=".csv" if conf.forms else ".txt") |
| 252 | os.close(handle) |
| 253 | |
| 254 | infoMsg = "writing crawling results to a temporary file '%s' " % filename |
| 255 | logger.info(infoMsg) |
| 256 | |
| 257 | with openFile(filename, "w+b") as f: |
| 258 | if conf.forms: |
| 259 | f.write("URL,POST\n") |
| 260 | |
| 261 | for url, _, data, _, _ in results: |
| 262 | if conf.forms: |
| 263 | f.write("%s,%s\n" % (safeCSValue(url), safeCSValue(data or ""))) |
| 264 | else: |
| 265 | f.write("%s\n" % url) |