ScrapeNinja

FREEMIUM
By Anthony | Updated hace 22 dรญas | Data
Popularity

9.9 / 10

Latency

3,727ms

Service Level

97%

Health Check

N/A

Back to All Discussions

302 status code, empty body

Rapid account: Even Lopez
EvenLopez
hace 2 aรฑos

I get a 302 status code response but with its body empty

Iโ€™m using scrapy so this is not the whole working code, I have another .py to instantiate this class and run .ninjaresponse() method. Anyway you can see the 302 status code in response.text, which doesnโ€™t return requested html

class ScrapeNinja():
ninja_url = โ€˜https://scrapeninja.p.rapidapi.com/scrapeโ€™

# get your subscription key at https://rapidapi.com/restyler/api/scrapeninja from "Code generator",
# copy&paste it to 'x-rapidapi-key' header below
def __init__(self,url):
    self.payload['url'] = url[0]
    self.payload['headers'][0] = f"referer: {url[0]}"

headers = {
    "Content-Type": "application/json",
    "x-rapidapi-host": "scrapeninja.p.rapidapi.com",
    "x-rapidapi-key": "xxxxx"
}

payload = {
    "url": "https://www.alcampo.es/compra-online/",
    "headers": [
        "authority: www.alcampo.es",
        "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "accept-language: es-ES,es;q=0.9",
        "cache-control: no-cache",
        "cookie: JSESSIONID2=1A0A02AA8CFE4A2AF33C7712B9D5816D.hybris5; cookieLanguageHybris=es; deliveryMode=PICKUP_DELIVERY_MODE; precode=\"\"; fastDelivery=false; localizedAs=anonymous; cookie_consent_user_accepted=true; cp=28041; shopId=015; selectionMode=selectedByUser; _gcl_au=1.1.400785008.1651759856; _fbp=fb.1.1651759856852.417292830; uid=e44ecd1602fb9d6bb0835119f5de97e2; sto__vuid=e44ecd1602fb9d6bb0835119f5de97e2; www._km_lead_collection=false; www._km_id=UMx05BiguxwLGXdh6EmW4QNsZiZLa028; www._km_user_name=Poised Otter; COOKIE_SUPPORT=true; GUEST_LANGUAGE_ID=es_ES; YOMe1hXPsDqscWomlSmem06yAMon28t8Vfv7k7W8mw__=v1LIaGSQ__RYl; __atuvc=1%7C18; __atssc=google%3B1; alcampoSpainStoreUid-cart=f0fbfbe2-7274-4018-9b45-89f27d4591c0; __utmzz=utmcsr=google|utmcmd=cpc|utmccn=(not set)|utmgclid=CjwKCAjwjtOTBhAvEiwASG4bCFVVnqN6G0brhb5LvH82wujqZ3cHxJMBUrfu31s--nRsJj9RACG1vxoCJxQQAvD_BwE; __utmzzses=1; __utmzze=utmcsr%3Dgoogle%7Cutmcmd%3Dcpc%7Cutmccn%3D(not%20set)%7Cutmgclid%3DCjwKCAjwjtOTBhAvEiwASG4bCFVVnqN6G0brhb5LvH82wujqZ3cHxJMBUrfu31s--nRsJj9RACG1vxoCJxQQAvD_BwE; client_ID=undefined; user_ID=undefined; chatbot_id=1A0A02AA8CFE4A2AF33C7712B9D5816D; cookie_consent_level=%7B%22strictly-necessary%22%3Atrue%2C%22functionality%22%3Atrue%2C%22tracking%22%3Atrue%2C%22targeting%22%3Atrue%7D; __cf_bm=TkT1xwvbRj.DLTHqUSctteXdVjEe6vCS1jLs6ymHFcY-1652254121-0-AaikEUiilcLEdjkm4VAWs0hezJdkTpU0zyU6H1NW7l95h+DCvfnPNjVYtP+FtZ6xpvUf00VvNWJre4eOXjfF9Xx/l6NGZccjAHan8VqfG1ypEOA5uGpG3/jtQVrepRKqN9qcBw+m9tcB50gbyG2JBqEKFGgjQOORW/AwQivXsGmd; sto__session=1652254123302; sto__count=0; cto_bundle=5b-hSl9YSmlmZmI1SXNKYklnUHh1b0htZzJWQ1c3OXFCTWFDRDByS2dyWkY3QVdQcXI5R0xqNDFCWHdnSm15OFZTcGN0Ym5QbzJFbEtPc0ZxdDFzUjNKWE5Gb1F2R2EzZWdWUmJiRnlHUUtWNzRXNCUyQkx1amdSc1RBY1FrdnNQWDM2QjRZZG53ZWlpN3FTcUpoemZJWHlpNUoydyUzRCUzRA; sid=c433ef73e2646bbfb57caa972662058f; _clck=po0ql7|1|f1d|0; _clsk=1ba9xg0|1652254124095|1|1|h.clarity.ms/collect",
        "pragma: no-cache",
        "sec-ch-ua: \" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
        "sec-ch-ua-mobile: ?0",
        "sec-ch-ua-platform: \"Windows\"",
        "sec-fetch-dest: document",
        "sec-fetch-mode: navigate",
        "sec-fetch-site: none",
        "sec-fetch-user: ?1",
        "upgrade-insecure-requests: 1",
        "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36"
    ]
}

def ninjaresponse(self):

    response = requests.request("POST", self.ninja_url, json=self.payload, headers=self.headers)
    test = 1
    return response
Rapid account: Even Lopez
EvenLopez Commented hace 2 aรฑos

I just tried running this code alone, apart from classes, and only then I get the right html. Only under classes I get this type of response.content (while response.status_code is 200):

bโ€™{โ€œinfoโ€:{โ€œversionโ€:โ€œ2โ€,โ€œstatusCodeโ€:302,โ€œstatusMessageโ€:"",โ€œheadersโ€:{โ€œdateโ€:โ€œWed, 11 May 2022 13:57:00 GMTโ€,โ€œcontent-lengthโ€:โ€œ0โ€,โ€œlocationโ€:"/compra-online/",โ€œcf-rayโ€:โ€œ709b6bd6481c1809-EWRโ€,โ€œstrict-transport-securityโ€:โ€œmax-age=2592000โ€,โ€œcf-cache-statusโ€:โ€œBYPASSโ€,โ€œcf-cache-debugโ€:"{\โ€œrequestCacheable\โ€:false,\โ€œresponseCacheable\โ€:false,\โ€œdeviceType\โ€:null,\โ€œresourceConfig\โ€:{\โ€œregex\โ€:{},\โ€œtype\โ€:\โ€œOTHER\โ€,\โ€œttl\โ€:3600},\โ€œisBot\โ€:false,\โ€œcacheKey\โ€:\โ€œhttps://www.alcampo.es/compra-onlineโ€“015false\",\โ€œsegment\โ€:\โ€œ015false\โ€}",โ€œcf-cache-debug-cookies-diffโ€:"{}",โ€œcf-cache-debug-requestโ€:"{\โ€œallowHitOnFirstAccess\โ€:true,\โ€œdpc\โ€:false,\โ€œsession\โ€:true,\โ€œbypass\โ€:true,\โ€œsegment\โ€:true,\โ€œorigin\โ€:true,\โ€œmethod\โ€:true}",โ€œcf-cache-debug-responseโ€:"{\โ€œedge\โ€:true,\โ€œstatus\โ€:false,\โ€œcookie\โ€:true}",โ€œcontent-security-policyโ€:"frame-ancestors http://.alcampo.es https://.alcampo.es *.publitas.comโ€,โ€œexpect-ctโ€:โ€œmax-age=604800, report-uri=\โ€œhttps://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\โ€โ€,โ€œx-content-type-optionsโ€:โ€œnosniffโ€,โ€œx-frame-optionsโ€:โ€œSAMEORIGINโ€,โ€œset-cookieโ€:["__cf_bm=dzI5yT.NIl3TDs4_HrWagcgtCp7aMNnr2tlpyRQb8zU-1652277420-0-AelXbmF37Q5Rn+x1FvMb5HdIMDDD3g0CxHlXMtddlnS1ZLSKfCNcp+4f42XMou29LZfZaNzq3ra4n+e5B8D6KAE=; path=/; expires=Wed, 11-May-22 14:27:00 GMT; domain=.alcampo.es; HttpOnly; Secure; SameSite=None"],โ€œvaryโ€:โ€œAccept-Encodingโ€,โ€œserverโ€:โ€œcloudflareโ€,โ€œalt-svcโ€:โ€œh3=\โ€:443\"; ma=86400, h3-29=\":443\"; ma=86400"}},โ€œbodyโ€:""}โ€™

Donโ€™t know what this exactly means but it is strongly bonded to classes

Rapid account: Restyler
restyler Commented hace 2 aรฑos

I am getting 200 page with html of the website, I have tested it several times, seems to work fineโ€ฆ

Join in the discussion - add comment below:

Login / Signup to post new comments