Python Scrapy Get HTML <script> tag

耗尽温柔 提交于 2019-12-02 08:02:22

Use Regex to do that

First grab the content of that SCRIPT tag like

response.css("script").extract_first()

And then use this regex

(Level\.cozum = )(.*?)(\;)

See demo here https://regex101.com/r/YxHRmR/1

This is code

import re
regex = r"(Level\.cozum = )(.*?)(\;)"

test_str = ("<script>\n"
    "      (function() {\n"
    "        ... / More Code\n"
    "        Level.grade = \"2\";\n\n"
    "        Level.level = \"1\";\n\n"
    "        Level.max_line = \"5\";\n\n"
    "        Level.cozum = 'adım 12\\ndön sağ\\nadım 13\\ndön sol\\nadım 11'; \n"
    "... / More Code\n"
    "</script>")

matches = re.findall(regex, test_str, re.MULTILINE)

print(matches)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!