GoogleScholarSwift
包提供了一个易于使用的接口,用于从 Google Scholar 获取出版物数据。它允许用户检索关于作者出版物的详细信息,包括标题、出版年份、链接和引用次数。此包专为学者、研究人员以及任何有兴趣以编程方式分析学术出版物数据的人员而设计。
要使用 Swift Package Manager 将 GoogleScholarSwift
集成到你的 Xcode 项目中,请将以下内容添加到你的 Package.swift
文件中
dependencies: [
.package(url: "https://github.com/ezefranca/GoogleScholarSwift.git", from: "1.2.0")
]
然后将 GoogleScholarSwift
作为依赖项添加到你的目标中
.target(
name: "YourTargetName",
dependencies: [
.product(name: "GoogleScholarSwift", package: "GoogleScholarSwift")
]
)
从 Google Scholar 获取给定作者的所有出版物。
public func fetchAllPublications(
authorID: GoogleScholarID,
fetchQuantity: FetchQuantity = .all,
sortBy: SortBy = .cited
) async throws -> [Publication]
authorID
: Google Scholar 作者 ID。fetchQuantity
: 要获取的出版物数量。可以是 .all
或 .specific(Int)
。 默认为 .all
。sortBy
: 出版物的排序标准。可以是 .cited
或 .pubdate
。默认为 .cited
。Publication
对象数组。let fetcher = GoogleScholarFetcher()
// Fetch all publications for a given author ID
let publications = try await fetcher.fetchAllPublications(authorID: GoogleScholarID("RefX_60AAAAJ"))
print(publications)
// Fetch a specific number of publications for a given author ID
let limitedPublications = try await fetcher.fetchAllPublications(authorID: GoogleScholarID("RefX_60AAAAJ"), fetchQuantity: .specific(10))
print(limitedPublications)
// Fetch all publications for a given author ID and sort by pubdate
let sortedPublications = try await fetcher.fetchAllPublications(authorID: GoogleScholarID("RefX_60AAAAJ"), sortBy: .pubdate)
print(sortedPublications)
获取特定文章的详细信息。
public func fetchArticle(articleLink: ArticleLink) async throws -> Article
articleLink
: 一个包含文章链接的 ArticleLink
对象。Article
对象。let fetcher = GoogleScholarFetcher()
let articleLink = ArticleLink(link: "https://scholar.google.com/citations?view_op=view_citation&hl=en&user=RefX_60AAAAJ&citation_for_view=RefX_60AAAAJ:9yKSN-GCB0IC")
let article = try await fetcher.fetchArticle(articleLink: articleLink)
print(article)
从 Google Scholar 获取作者的详细信息,例如姓名、单位和头像 URL。
public func fetchAuthorDetails(scholarID: GoogleScholarID) async throws -> Author
scholarID
: Google Scholar 作者 ID。Author
对象。let fetcher = GoogleScholarFetcher()
let AuthorDetails = try await fetcher.fetchAuthorDetails(scholarID: GoogleScholarID("6nOPl94AAAAJ"))
print(AuthorDetails)
import GoogleScholarSwift
let fetcher = GoogleScholarFetcher()
let authorID = GoogleScholarID("RefX_60AAAAJ")
// Fetch all publications for a given author ID
let publications = try await fetcher.fetchAllPublications(authorID: authorID)
print("All Publications:", publications)
// Fetch a specific number of publications for a given author ID
let limitedPublications = try await fetcher.fetchAllPublications(authorID: authorID, fetchQuantity: .specific(10))
print("Limited Publications:", limitedPublications)
// Fetch all publications for a given author ID and sort by pubdate
let sortedPublications = try await fetcher.fetchAllPublications(authorID: authorID, sortBy: .pubdate)
print("Sorted Publications:", sortedPublications)
// Fetch article details for the first publication
if let firstPublication = publications.first {
let articleLink = ArticleLink(link: firstPublication.link)
let article = try await fetcher.fetchArticle(articleLink: articleLink)
print("Article Details:", article)
}
// Fetch Author details
let AuthorDetails = try await fetcher.fetchAuthorDetails(scholarID: authorID)
print("Author Details:", AuthorDetails)
我们欢迎对 GoogleScholarSwift
的贡献! 如果您有改进建议,请提交问题或拉取请求。
本项目与 Google 无关,仅供教育目的。 使用和解释通过本项目获得的数据的责任完全由用户承担。 本项目的开发人员和贡献者不对因使用所提供数据而引起的任何滥用或法律影响负责。 建议用户在使用本项目时确保遵守适用的法律和法规。
GoogleScholarSwift
在 MIT 许可证下发布。 有关更多详细信息,请参见 LICENSE 文件。