0

I want to fetch data from https://virgool.io/feed/@jEbrahimi and show data in Some list

fetch('https://virgool.io/feed/@jEbrahimi', { 'mode': 'no-cors' })
  .then(xml => xml.text())
  .then(xmlText => {
     var domParser = new DOMParser()
     let doc = domParser.parseFromString(xmlText, 'text/xml')
     console.log('doc: ', doc);
   })
   .catch(() => console.error('Error in fetching the website'))

i get nothing with this code

i want to get title text and link href in xml file

<title type="text"><![CDATA[استفاده از ری اکت بدون Node.js]]></title>
<link rel="alternate" type="text/html" 
href="https://virgool.io/@jEbrahimi/try-react-without-nodejs- 
mjscaihovuqa"></link>

how can i get the data and show them in the list whit <a> tag:

<div className='lastArticle'>
  <a href='https://virgool.io/@jEbrahimi/try-react-without-nodejs- 
   mjscaihovuqa'>استفاده ار ری‌اکت بدون NodeJS</a>
</div>
Javad Ebrahimi
  • 199
  • 3
  • 11
  • Can you guarantee that the HTML returned from the site will be XML? Remember, XML is far, far stricter than HTML, as browsers will ignore things like `
    ` (for example) when XML will throw an error because it expects `
    `
    – freefaller May 07 '19 at 07:24
  • You can use libraries like xml2js to convert xml to javascript object. https://www.npmjs.com/package/xml2js – Chetan Khilosiya May 07 '19 at 07:28
  • @freefaller thank you for your guide. is there any way to got data from that link? – Javad Ebrahimi May 07 '19 at 07:29
  • @freefaller and yes it's always return a xml file – Javad Ebrahimi May 07 '19 at 07:47
  • @JavadEbrahimi I think your issue would be extracting the data from the xml string returned. Correct me if I am wrong. – philip_nunoo May 07 '19 at 07:57
  • Sorry, can't help with your specific question, just wanted to raise a possible issue with HTML vs XML. Good luck – freefaller May 07 '19 at 07:58
  • Why have you set `{ 'mode': 'no-cors' }`? That is only useful when you are making a cross-origin opaque request. Since you are trying to read the response, you can't be making an opaque request. – Quentin May 07 '19 at 08:03
  • @philip_nunoo i can't extracting the data form that link, i looking for a way to get data – Javad Ebrahimi May 07 '19 at 08:04
  • You said "i get nothing with this code" but I can't see any circumstance where that would not either give you the desired document object or error messages on the browser's Console. – Quentin May 07 '19 at 08:06
  • Are you running this JavaScript in an HTML document hosted on `https://virgool.io/` ? – Quentin May 07 '19 at 08:07
  • @Quentin if i remove ` { 'mode': 'no-cors' } i got `set the request's mode to 'no-cors' to fetch the resource with CORS disabled` error, i add this to remove the error – Javad Ebrahimi May 07 '19 at 08:08
  • @JavadEbrahimi – That message should also tell you that that will only help if an opaque request is acceptable to you. Since you need to read the response, and opaque request **isn't** acceptable to you. – Quentin May 07 '19 at 08:10
  • @JavadEbrahimi please use the following gist and see if it helps. https://gist.github.com/Philip-Nunoo/85357e0dd09293aeecc5105922a110f1 – philip_nunoo May 07 '19 at 08:20
  • @Quentin Thank's, virgool is website like medium and i write my article on virgool. now i want to create section on my website to show my virgool article. and this link `https://virgool.io/feed/@jEbrahimi` is my account rss link, is there any way to show article in my website? – Javad Ebrahimi May 07 '19 at 08:21
  • @Quentin no i get `Access to XMLHttpRequest at 'https://virgool.io/feed/@jEbrahimi' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.` error – Javad Ebrahimi May 07 '19 at 08:27
  • @JavadEbrahimi — Then virgool isn't giving localhost permission to read the data. See the duplicate. – Quentin May 07 '19 at 08:32
  • @Quentin You Are a Good Man, Thank You. – Javad Ebrahimi May 07 '19 at 08:36

0 Answers0