private void DownloadData(string word) { WebClient client = new WebClient(); client.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"); try { String url = $"https://www.howtopronounce.com/{word}/"; String html = Encoding.UTF8.GetString(client.DownloadData(url)); List <String> audioURL = GetAudioURL(html); if (audioURL.Count > 0) { TrainingEntry entry = null; lock (this) { entry = ds.GetEntry(word); } entry.Word = word; entry.Phonetics = ""; lock (this) { totalEntryCount++; } String path = @"d:\" + Convert.ToBase64String(Encoding.ASCII.GetBytes(word)).Replace("=", "") .Replace("/", "").Replace("\\", "") + ".mp3"; foreach (String u in audioURL) { client.DownloadFile(u, path); entry.AddAudio(path, "HowToPronounce@" + url); lock (this) { totalAudioCount++; } File.Delete(path); } Console.WriteLine($"{totalEntryCount} -> {totalAudioCount}"); } } catch (Exception ex) { int h = 0; } }
private void DownloadData(string url) { WebClient client = new WebClient(); try { String html = Encoding.UTF8.GetString(client.DownloadData(url)); String audioURL = GetAudioURL(html); if (audioURL != null) { String path = @"d:\" + Convert.ToBase64String(Encoding.ASCII.GetBytes(audioURL)).Replace("=", "") .Replace("/", "").Replace("\\", "") + ".mp3"; String word = GetWord(html); String phonetics = GetPhonetics(html).Trim(); if (phonetics != null) { client.DownloadFile(audioURL, path); TrainingEntry entry = null; lock (this) { entry = ds.GetEntry(word); } entry.Word = word; entry.Phonetics = phonetics; entry.AddAudio(path, "Longman@" + url); lock (this) { totalCount++; } Console.WriteLine(totalCount); File.Delete(path); } } } catch (Exception ex) { int h = 0; } }