J'essaie la méthode DownloadData
à partir du WebClient
. Mon problème actuel est que je ne l'ai pas été en mesure de savoir comment convertir les ASCII
result (<
-<
, \n
, >
->
) qui est produit à partir Encoding.ASCII.GetString(myDataBuffer);
, de ce page.Encodage ASCII en HTML
pagesource http://iforce.co.nz/i/z4f2wggp.evi.png
/// <summary>
/// Curl data from the PMID
/// </summary>
private void ClientPMID(int pmid)
{
//generate the URL for the client
StringBuilder pmid_url_string = new StringBuilder();
pmid_url_string.Append("http://www.ncbi.nlm.nih.gov/pubmed/").Append(pmid.ToString()).Append("?report=xml");
Uri PMIDUri = new Uri(pmid_url_string.ToString());
//declare and initialize the client
WebClient client = new WebClient();
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = client.DownloadData(PMIDUri);
this.DownloadCompleted(myDataBuffer);
}
/// <summary>
/// Crawl over the binary from myDataBuffer
/// </summary>
/// <param name="myDataBuffer">Binary Buffer</param>
private void DownloadCompleted(byte[] myDataBuffer)
{
string download = Encoding.ASCII.GetString(myDataBuffer);
PMIDCrawler pmc = new PMIDCrawler(download, "/pre/PubmedArticle/MedlineCitation/Article");
//iterate over each node in the file
foreach (XmlNode xmlNode in pmc.crawl)
{
string AbstractTitle = xmlNode["ArticleTitle"].InnerText;
string AbstractText = xmlNode["Abstract"]["AbstractText"].InnerText;
}
}
Code pour PMIDCrawler est disponible sur mon autre question concernant le SO DownloadStringCompletedEventHandler
. Bien que la sortie de string html = HttpUtility.HtmlDecode(nHtml);
ne soit pas valide HTML (OR XML) (en raison de ne pas répondre à xml
en-têtes http), après avoir reçu le contenu de Encoding.ASCII.GetString
.
Voici comment le faire avec javascript par exemple http://stackoverflow.com/questions/5796718/html-entity-decode – Hogan