I want to write a crawler that crawls the image of the petal net. When Ajax is used to obtain data, the request URL in the image is returned. the Response text type is json. However, when I access this url separately, it is html. how can I obtain json data?
I want to write a crawler that crawls the image of the petal net. An error occurred while obtaining data through Ajax.
The request URL in the image. The text type of Response is json.
But when I access this url separately, it is html
How to obtain json data
Reply content:
I want to write a crawler that crawls the image of the petal net. An error occurred while obtaining data through Ajax.
The request URL in the image. The text type of Response is json.
But when I access this url separately, it is html
How to obtain json data
This is controlled by the header.
You can add the corresponding request header. Attach 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 Header used to prevent webpages from being obtained outside the site. when crawling, make sure that Referer settings are correct.