0
#Python Code
from bs4 import BeautifulSoup
import urllib3

url ='https://www. SomeData .com'
req = urllib3.PoolManager()
res = req.request('GET', url)
soup = BeautifulSoup(res.data, 'html.parser')
res = soup.find_all('script')
print(res)

Then I Got something like this:

Results below:
[
  <script>
        AAA.trackData.taxonomy = {
              a:"a",
              b:"b",
              c:"c2,
              ...} ;
</script>
</script>, <script async="" src="https://someData.com/js/detail.0a6eca28.js"></script>
]

How can i convert this to a json format to treat well data inside tag.

1
  • Whats your desired output? Commented Jul 27, 2019 at 12:16

1 Answer 1

0

Please check if this helps.

script = soup.find('script', text=re.compile('AAA\.trackData\.taxonomy'))
json_text = re.search(r'^\s*AAA\.trackData\.taxonomy\s*=\s*({.*?})\s*;\s*$',
                      script.string, flags=re.DOTALL | re.MULTILINE).group(1)
data = json.loads(json_text)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.