Python Code To Get JSON From Javascript And Load Into A Dictionary | Web Scraping tutorial

Опубликовано: 01 Январь 1970
на канале: jobstr
467
8

How to parse response.text from Scrapy, (or requests, or Beautiful Soup).
(No regular expressions needed, just split, strip, replace).

If you find that you are trying to scrape comments from a page, and they're inside javascript then you will need a way to get the values/text some other way. CSS or XPATH won't help you.

Here I show how to parse the javascript to pick out the JSON, and then load the JSON into a dictionary. Once the key:values are there, you can work with them very easily.

◉ 1:26 looking for JSON
◉ 2:19 view source
◉ 2:55 found JSON.parse
◉ 4:45 found comments inside JSON
◉ 5:29 print(response.text)

◉ 6:09 x = response.text.split('JSON.parse')[2].replace("\\u0022","\"").lstrip("\(").split(" ")[0].replace("}\");","\"").replace("\"{","\""})
◉ 8:43 json.loads
◉ 12:27 final output

Read about the process of extracting a dict from json from javascript on my redandgreen.co.uk website : https://redandgreen.co.uk/extracting-...

RTFM 📙 :
https://docs.scrapy.org/en/latest/
https://docs.scrapy.org/en/latest/top...

☕️☕️☕️ Buy Dr Pi a Coffee...or Tea! : https://www.buymeacoffee.com/DrPi ☕️☕️☕️

Thanks for watching.
See you around yeah?
Dr P.


На этой странице сайта вы можете посмотреть видео онлайн Python Code To Get JSON From Javascript And Load Into A Dictionary | Web Scraping tutorial длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь jobstr 01 Январь 1970, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 467 раз и оно понравилось 8 зрителям. Приятного просмотра!