import urllib.request import json import os out_dir = "/home/admin/GBS_Research/学术论文" os.makedirs(out_dir, exist_ok=True) queries = [ "shared services value creation", "shared service center multinational", "global business services GBS", "financial shared services China", "shared services digital transformation", "shared services compliance cross-border", "shared services cost efficiency", "business process reengineering shared services", ] all_papers = {} for q in queries: url = f"https://api.openalex.org/works?search={urllib.parse.quote(q)}&per_page=15&sort=cited_by_count:desc" try: req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0", "Accept": "application/json"}) with urllib.request.urlopen(req, timeout=30) as resp: data = json.loads(resp.read().decode()) for w in data.get("results", []): doi = w.get("doi", "") if doi in all_papers: continue abstract_inv = w.get("abstract_inverted_index", {}) if abstract_inv: pairs = [] for word, positions in abstract_inv.items(): for pos in positions: pairs.append((pos, word)) pairs.sort() abstract = " ".join(pw for _, pw in pairs) else: abstract = "" all_papers[doi] = { "title": w.get("title", ""), "doi": doi, "year": w.get("publication_year", ""), "cited_by_count": w.get("cited_by_count", 0), "authors": [a.get("author",{}).get("display_name","") for a in w.get("authorships",[])], "source": w.get("primary_location",{}).get("source",{}).get("display_name","") if w.get("primary_location") else "", "abstract": abstract, "query": q, } print(f"✓ {q}: {data.get('meta',{}).get('count',0)} total, got {len(data.get('results',[]))}") except Exception as e: print(f"✗ {q}: {e}") # Sort by citations papers = sorted(all_papers.values(), key=lambda x: x.get("cited_by_count",0), reverse=True) # Save JSON with open(f"{out_dir}/openalex_papers.json", "w", encoding="utf-8") as f: json.dump(papers, f, ensure_ascii=False, indent=2) # Save markdown summary lines = ["# GBS/共享服务中心 学术论文汇总 (OpenAlex)\n"] lines.append(f"共找到 {len(papers)} 篇不重复论文\n") lines.append("| # | 标题 | 年份 | 被引 | DOI |") lines.append("|---|------|------|------|-----|") for i, p in enumerate(papers[:80], 1): title = p["title"][:80] if p["title"] else "N/A" doi_link = f"https://doi.org/{p['doi'].replace('https://doi.org/','')}" if p["doi"] else "" lines.append(f"| {i} | {title} | {p['year']} | {p['cited_by_count']} | {doi_link} |") lines.append("\n---\n## 详细摘要\n") for i, p in enumerate(papers[:80], 1): lines.append(f"### {i}. {p['title']}") lines.append(f"- **年份**: {p['year']} | **被引**: {p['cited_by_count']}") lines.append(f"- **期刊**: {p['source']}") lines.append(f"- **作者**: {', '.join(p['authors'][:5])}") lines.append(f"- **DOI**: {p['doi']}") lines.append(f"- **摘要**: {p['abstract'][:500]}") lines.append("") with open(f"{out_dir}/openalex_summary.md", "w", encoding="utf-8") as f: f.write("\n".join(lines)) print(f"\n总论文数: {len(papers)}, 有摘要: {sum(1 for p in papers if p['abstract'])}") print(f"Top cited: {papers[0]['title'][:60]} ({papers[0]['cited_by_count']} cites)" if papers else "")