import Foundation
class Scraper {
private static let API_KEY = "YOUR_API_KEY"
private static let BASE_URL = "https://api.scrapecreators.com"
private static let ENDPOINT_PATH = "/v1/linkedin/ads/search"
static func scrape(completion: @escaping (Result<String, Error>) -> Void) {
// Build query parameters
var components = URLComponents(string: BASE_URL + ENDPOINT_PATH)!
components.queryItems = [
URLQueryItem(name: "company", value: "microsoft"),
URLQueryItem(name: "keyword", value: "scraping"),
URLQueryItem(name: "countries", value: "US,CA,MX"),
URLQueryItem(name: "startDate", value: "2024-01-01"),
URLQueryItem(name: "endDate", value: "2024-01-10"),
URLQueryItem(name: "paginationToken", value: "640547184-1743616612000")
]
guard let url = components.url else {
completion(.failure(NSError(domain: "Invalid URL", code: -1, userInfo: nil)))
return
}
var request = URLRequest(url: url)
request.setValue(API_KEY, forHTTPHeaderField: "x-api-key")
URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
completion(.failure(error))
return
}
guard let data = data else {
completion(.failure(NSError(domain: "No data", code: -1, userInfo: nil)))
return