AJax data acquisition by crawlers

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.