Wikipedia JSONP-페이지 ID 추출

Borni

페이지의 모든 데이터를 jsonp로 가져 오는 방법을 알아 내려고 노력했습니다. 현재 올바른 링크가 있지만 두 가지 문제가 발생했습니다. 이것은 jsonp를받는 데 사용하는 URL입니다 (예 : 스택 오버플로 사용).

https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=stack%20overflow&format=json&callback=JSONP_CALLBACK

첫 번째 문제 : res.data를 수행 할 때 모든 정보를 얻었지만 페이지 번호를 전달하는 방법을 알아낼 수없는 것 같습니다.

JSONP_CALLBACK (
{
"batchcomplete": "",
"query": {
"normalized": [
{
"from": "stack overflow",
"to": "Stack overflow"
}
],
"pages": {
"1436888": { // This is where I get stuck..
"pageid": 1436888,
"ns": 0,
"title": "Stack overflow",
"extract": "<p>In software, a <b>stack overflow</b> occurs if the call stack pointer exceeds the stack bound. The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to <i>overflow</i>, typically resulting in a program crash.</p>\n<p></p>\n<h2><span id=\"Infinite_recursion\">Infinite recursion</span></h2>\n\n<p>The most common cause of stack overflow is excessively deep or infinite recursion, in which a function calls itself so many times that the space needed to store the variables and information associated with each call is more than can fit on the stack.</p>\n<p>An example of infinite recursion in C.</p>\n\n<p>The function <i>foo</i>, when it is invoked, continues to invoke itself, allocating additional space on the stack each time, until the stack overflows resulting in a segmentation fault. However, some compilers implement tail-call optimization, allowing infinite recursion of a specific sort—tail recursion—to occur without stack overflow. This works because tail-recursion calls do not take up additional stack space.</p>\n<p>C compiler options will effectively enable tail-call optimization; compiling the above simple program using gcc with <code>-O1</code> will result in a segmentation fault, but not when using <code>-O2</code> or <code>-O3</code>, since these optimization levels imply the <code>-foptimize-sibling-calls</code> compiler option. Other languages, such as Scheme, require all implementations to include tail-recursion as part of the language standard.</p>\n<h2><span id=\"Very_deep_recursion\">Very deep recursion</span></h2>\n<p>A recursive function that terminates in theory but causes a call stack buffer overflow in practice can be fixed by transforming the recursion into a loop and storing the function arguments in a stack. This is always possible, because the class of primitive recursive functions is equivalent to the class of LOOP computable functions. Consider this example in C++-like pseudocode:</p>\n<p>A primitive recursive function like the one on the left side can always be transformed into a loop like on the right side.</p>\n<h2><span id=\"Very_large_stack_variables\">Very large stack variables</span></h2>\n<p>The other major cause of a stack overflow results from an attempt to allocate more memory on the stack than will fit, for example by creating local array variables that are too large. For this reason some authors recommend that arrays larger than a few kilobytes should be allocated dynamically instead of as a local variable.</p>\n<p>An example of a very large stack variable in C:</p>\n\n<p>The declared array consumes 8 mebibytes of data (assuming each double is 8 bytes); if this is more memory than is available on the stack (as set by thread creation parameters or operating system limits), a stack overflow will occur.</p>\n<p>Stack overflows are made worse by anything that reduces the effective stack size of a given program. For example, the same program being run without multiple threads might work fine, but as soon as multi-threading is enabled the program will crash. This is because most programs with threads have less stack space per thread than a program with no threading support. Because kernels are generally multi-threaded, people new to kernel development are usually discouraged from using recursive algorithms or large stack buffers.</p>\n<h2><span id=\"See_also\">See also</span></h2>\n\n<ul><li>Buffer overflow</li>\n<li>Call stack</li>\n<li>Heap overflow</li>\n<li>Stack buffer overflow</li>\n<li>Double fault</li>\n</ul><h2><span id=\"References\">References</span></h2>\n\n<p>Kernel Programming Guide https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KernelProgramming/KernelProgramming.pdf</p>\n<h2><span id=\"External_links\">External links</span></h2>\n<ul><li>The reasons why 64-bit programs require more stack memory</li>\n</ul>"
    }
   }
  }
 }
)

내 결과로 다음과 같은 결과를 얻을 수 있습니다. res.data.query.pages하지만 당연히 페이지 ID 번호 (무작위)에 도달하면 정보를 얻는 방법을 알아낼 수없는 것 같습니다.

문제 2 : 분명히 extractjsonp에서 가져 오고 싶지만 위에서 보았 듯이이 모든 태그가 포함되어 있으며 좋은 출력을 제공하지 않습니다. html로 표시하는 방법이 있습니까?

보그 단 룽구

페이지 ID를 추출하려면 다음 코드를 사용할 수 있습니다.

var theObj = res.data.query.pages;
var thePageId = theObj[Object.keys(theObj)[0]].pageid;
// Object.keys(theObj)[0] will extract the value of the first property which is variable in your case and you don't know it. So we have the object which we know it has the property "pageid".

여기에 페이지 ID를 알리는 바이올린이 있습니다 : https://jsfiddle.net/fg6mdrxj/

두 번째 문제와 관련하여 속성의 가치를 얻으면 쉽게 조작 할 수 있습니다. 동일한 바이올린에서 여기에 업데이트가 있습니다. https://jsfiddle.net/fg6mdrxj/1/ 추출 속성의 값을 가져와 ID 추출과 함께 div에 추가합니다.

JS :

var toHtml = theObj[Object.keys(theObj)[0]].extract;
document.getElementById("extract").innerHTML = toHtml;

HTML :

<div id="extract"></div>

물론 추출의 가치는 일단 얻은 후에 다른 방식으로 조작 할 수 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Wikipedia Infobox 데이터 추출

분류에서Dev

JSONP없이 API 호출

분류에서Dev

Wikipedia API에서 테이블 데이터 추출

분류에서Dev

R의 wikipedia에서 특정 테이블 추출

분류에서Dev

Wikipedia에서 사람 날짜 데이터 추출

분류에서Dev

Javascript는 Wikipedia API에서 데이터를 추출합니다.

분류에서Dev

JSONP로 Wikipedia API에 액세스

분류에서Dev

API를 통해 Wikipedia 페이지에서 이미지와 추출에 모두 액세스하는 방법은 무엇입니까?

분류에서Dev

정규식을 사용하여 HTML 페이지에서 href ID 추출

분류에서Dev

이미지 경로에서 ID 추출

분류에서Dev

Wikipedia API는 CORS를 지원합니까 아니면 JSONP 만 사용할 수 있습니까?

분류에서Dev

Wikipedia 페이지의 엔티티 식별

분류에서Dev

Wikipedia, badtoken의 페이지 편집

분류에서Dev

Wikipedia 페이지보기 통계 얻기

분류에서Dev

JSONP 403 금지

분류에서Dev

긴 URL에서 페이스 북 사진 ID 추출

분류에서Dev

Javascript Wikipedia 요약 추출 오류

분류에서Dev

Angular 8 jsonp 콜백이 호출되지 않았습니다.

분류에서Dev

Firefox jquery ajax JSONP 호출이 작동하지 않음

분류에서Dev

RESTful json API의 백본 JSONP 호출이 작동하지 않음

분류에서Dev

웹 페이지에서 ID 목록을 추출하려면 어떻게해야합니까?

분류에서Dev

한 줄에서 이메일 ID 추출

분류에서Dev

DBPedia를 사용하여 Wikipedia 정보 상자 데이터를 추출하는 SPARQL 쿼리

분류에서Dev

jquery 모바일의 ID에 페이지 추가

분류에서Dev

페이지에 새 요소를 추가 할 때 HTML ID 문제

분류에서Dev

현재 페이지의 ID를 href에 자동으로 추가

분류에서Dev

현재 페이지의 ID를 href에 자동으로 추가

분류에서Dev

콜백 함수는 JSONP에서 호출되지 않습니다.

분류에서Dev

Ruby on Rails에서 JSONP에 대한 서버 측 지원 추가

Related 관련 기사

  1. 1

    Wikipedia Infobox 데이터 추출

  2. 2

    JSONP없이 API 호출

  3. 3

    Wikipedia API에서 테이블 데이터 추출

  4. 4

    R의 wikipedia에서 특정 테이블 추출

  5. 5

    Wikipedia에서 사람 날짜 데이터 추출

  6. 6

    Javascript는 Wikipedia API에서 데이터를 추출합니다.

  7. 7

    JSONP로 Wikipedia API에 액세스

  8. 8

    API를 통해 Wikipedia 페이지에서 이미지와 추출에 모두 액세스하는 방법은 무엇입니까?

  9. 9

    정규식을 사용하여 HTML 페이지에서 href ID 추출

  10. 10

    이미지 경로에서 ID 추출

  11. 11

    Wikipedia API는 CORS를 지원합니까 아니면 JSONP 만 사용할 수 있습니까?

  12. 12

    Wikipedia 페이지의 엔티티 식별

  13. 13

    Wikipedia, badtoken의 페이지 편집

  14. 14

    Wikipedia 페이지보기 통계 얻기

  15. 15

    JSONP 403 금지

  16. 16

    긴 URL에서 페이스 북 사진 ID 추출

  17. 17

    Javascript Wikipedia 요약 추출 오류

  18. 18

    Angular 8 jsonp 콜백이 호출되지 않았습니다.

  19. 19

    Firefox jquery ajax JSONP 호출이 작동하지 않음

  20. 20

    RESTful json API의 백본 JSONP 호출이 작동하지 않음

  21. 21

    웹 페이지에서 ID 목록을 추출하려면 어떻게해야합니까?

  22. 22

    한 줄에서 이메일 ID 추출

  23. 23

    DBPedia를 사용하여 Wikipedia 정보 상자 데이터를 추출하는 SPARQL 쿼리

  24. 24

    jquery 모바일의 ID에 페이지 추가

  25. 25

    페이지에 새 요소를 추가 할 때 HTML ID 문제

  26. 26

    현재 페이지의 ID를 href에 자동으로 추가

  27. 27

    현재 페이지의 ID를 href에 자동으로 추가

  28. 28

    콜백 함수는 JSONP에서 호출되지 않습니다.

  29. 29

    Ruby on Rails에서 JSONP에 대한 서버 측 지원 추가

뜨겁다태그

보관