I want to write a crawler that crawls pictures of petal nets. I'm having problems with Ajax getting data.
The text type of the requested url,response in the picture is JSON
But when I visit this URL alone, it's HTML.
How to get JSON data
Reply content:
I want to write a crawler that crawls pictures of petal nets. I'm having problems with Ajax getting data.
The text type of the requested url,response in the picture is JSON
But when I visit this URL alone, it's HTML.
How to get JSON data
This is controlled by the header.
You'll have to add the corresponding request header. Attached to My Code
#coding=utf-8import requests as RQhburl = "http://huaban.com/boards/28195582/?ipva9fpx&max=759391397&limit=20&wfl=1"heads = {'Host':"huaban.com",'Referer':"{http://huaban.com/boards/28195582/",'User-Agent':"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36",'X-Request':"JSON",'X-Requested-With':"XMLHttpRequest"}print RQ.get(hburl, headers=heads).content
Rerferer is a common used to prevent web pages from being taken out of the header, do the crawler must ensure that the Referer settings