import re, json, subprocess, html, time, datetime def get(u): return subprocess.run(['curl','-s','-m','40','-A','Mozilla/5.0',u],capture_output=True,text=True).stdout G='sci.crypt' threads={} log=open('crawl.log','a') for y in range(1996,2013): for (a,b) in [('01-01','04-01'),('04-01','07-01'),('07-01','10-01'),('10-01','12-31')]: q=f'author%3Ahopwood%20after%3A{y}-{a}%20before%3A{y}-{b}' h=get(f'https://groups.google.com/g/{G}/search?q={q}') ts=sorted(set(re.findall(r'href="\./g/'+re.escape(G)+r'/c/([A-Za-z0-9_-]+)',h))) for t in ts: threads.setdefault(t,f'{y}-{a}') print(y,a,len(ts),file=log,flush=True) time.sleep(0.5) json.dump(threads,open('threads.json','w')) print('threads',len(threads),file=log,flush=True) out=[] for i,t in enumerate(threads): h=get(f'https://groups.google.com/g/{G}/c/{t}') for sec in re.split(r'(?=
([^<]+)',sec) mid=re.search(r'data-doc-id="([^"]+)"',sec) body=re.search(r'
(.*?)
',sec,re.S) out.append(dict(thread=t,msg=mid.group(1) if mid else None,author=html.unescape(au.group(1)),date_disp=dt.group(1) if dt else None, subject=html.unescape((re.search(r'data-subject="([^"]*)"',sec) or [None,''])[1]),body_html=body.group(1) if body else None, url=f'https://groups.google.com/g/{G}/c/{t}/m/{mid.group(1) if mid else ""}')) if i%20==0: print('thr',i,len(out),file=log,flush=True) time.sleep(0.3) json.dump(out,open('gg_msgs.json','w')) print('done',len(out),file=log,flush=True)