0

This is the html script I get when I use requests.

<script type="text/javascript">
$(document).ready(function(){
        data = [{"str":"안녕하세요+저는+예상우+입니다","errInfo":[{"help":"입력 오류입니다.","errorIdx":0,"correctMethod":1,"start":9,"end":12,"orgStr":"예상우","candWord":"예상외"}],"idx":0}];
        pageIdx = 0;
        /*<![CDATA[*/
        if(1){
                totalPageCnt = 1;
        }
        /*]]>*/
        data = eval(data);

        makeHTML(0);

        if(totalPageCnt != 1){
                if(pageIdx == 0){
                        toast("총 " +totalPageCnt+"페이지입니다. 아래 화살표를 이용해 이동해주세요.");
                }

                document.getElementById('pageAnnounce').innerHTML = "총 " +totalPageCnt+"페이지 중 " + (pageIdx+1) +"페이지입니다.<br>화살표를 눌러 페이지를 이동해주세요.";
        }
});
</script>

I want to get str,help,errorIdx,correctMethod,start,end,orgStr,candWordfrom this javascript with python. How can I do this?

1 Answer 1

1

Try this,

import re
import json
from bs4 import BeautifulSoup

soup = BeautifulSoup(text, "html.parser")

script = soup.find('script')
data = json.loads(re.search("data = (.*);", script.text).group(1))

print(data[0]['str'])

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.