ScraperConfig.fromMap constructor
Creates a ScraperConfig instance from a Map.
This factory constructor is used for deserializing configuration from JSON or other map-based formats.
Parameters:
map
: Map containing configuration data
Returns:
- New ScraperConfig instance with data from the map
Implementation
factory ScraperConfig.fromMap(Map<String, dynamic> map) {
return ScraperConfig(
pathPatterns: List<String>.from(map['pathPatterns']),
requiresHtml: map['requiresHtml'] ?? true,
urlCleaner: map['urlCleaner'] != null
? UrlCleaner.fromMap(map['urlCleaner'])
: null,
parsers: (map['parsers'] as List)
.map((parser) => Parser.fromMap(parser))
.toList(),
proxyAPIConfig: map['proxyAPIConfig'] != null
? ProxyAPIConfig.fromMap(map['proxyAPIConfig'])
: null,
cookies: map['cookies'] != null
? Map<String, String>.from(map['cookies'])
: null,
headers: map['headers'] != null
? Map<String, String>.from(map['headers'])
: null,
forceRefresh: map['forceRefresh'] ?? false,
userAgent: map['userAgent'] != null
? UserAgentDevice.values.firstWhere(
(e) => e.toString() == 'UserAgentDevice.${map['userAgent']}',
orElse: () => UserAgentDevice.mobile,
)
: UserAgentDevice.mobile,
);
}