Может ли кто-нибудь объяснить мне, почему ответ fetch отличается, когда я делаю тесты на android и когда я делаю то же самое на iphone? Это вызывает у меня проблемы при извлечении текста для использования библиотекой cheerio.
В android Я могу идеально извлечь данные, чего не происходит на iPhone, что я делаю неправильно или что Я проигрываю?
Большое спасибо за любой мудрый ответ.
Код:
import React, { Component } from "react";
import { TextInput, Button } from "react-native";
import { View } from "native-base";
export default function SearchLinkText() {
const [value, onChangeText] = React.useState("");
const cheerio = require("react-native-cheerio");
async function loadHTML() {
const searchUrl =
"https://www.amazon.es/Bear-Village%C2%AE-Billetera-Magn%C3%A9tico-Plegable/dp/B0834Z8V2V/ref=sr_1_8?
__mk_es_ES=%C3%85M%C3%85%C5%BD%C3%95%C3%91&keywords=funda+galaxy&qid=1579629120&s=kitchen&sr=1-8";
const response = await fetch(searchUrl); // fetch page
const htmlString = await response.text(); // get response text
const $ = cheerio.load(htmlString, { decodeEntities: false }); // parse HTML string
console.log('Full HTML:' + htmlString)
console.log(
"Title: " +
$("h1.a-size-large span.a-size-large")
.html()
.trim()
);
console.log(
"Price: " +
$("div.a-section div.feature span.a-size-medium.a-color-price")
.html()
.trim()
);
}
return (
<View
style={{
flexDirection: "row",
justifyContent: "space-between",
margin: 20
}}
>
<TextInput
style={{ height: 40, borderColor: "gray", borderWidth: 1, width: 250 }}
placeholder="Paste Link"
onChangeText={text => onChangeText(text)}
value={value}
/>
<Button title="Get" onPress={loadHTML} />
</View>
);
}
Android ответ (Console.log):
console.log ('Full HTML:' + htmlString) первые 30 строк :
<!doctype html><html class="a-no-js" data-19ax5a9jf="dingo">
<head>
<script type="text/javascript">var ue_t0=ue_t0||+new Date();</script>
<script type="text/javascript">
window.ue_ihb = (window.ue_ihb || window.ueinit || 0) + 1;
if (window.ue_ihb === 1) {
var ue_hob=+new Date();
var ue_id='3K2TJQ58BVNQN3K7EHVJ',
ue_csm = window,
ue_err_chan = 'jserr-rw',
ue = {};
(function(d){var e=d.ue=d.ue||{},f=Date.now||function(){return+new Date};e.d=function(b){return f()-(b?0:d.ue_t0)};e.stub=function(b,a){if(!b[a]){var c=[];b[a]=function(){c.push([c.slice.call(arguments),e.d(),d.ue_id])};b[a].replay=function(b){for(var a;a=c.shift();)b(a[0],a[1],a[2])};b[a].isStub=1}};e.exec=function(b,a){return function(){try{return b.apply(this,arguments)}catch(c){ueLogError(c,{attribution:a||"undefined",logLevel:"WARN"})}}}})(ue_csm);
ue.stub(ue,"log");ue.stub(ue,"onunload");ue.stub(ue,"onflush");
(function(d,e){function h(f,b){if(!(a.ec>a.mxe)&&f){a.ter.push(f);b=b||{};var c=f.logLevel||b.logLevel;c&&c!==k&&c!==m&&c!==n&&c!==p||a.ec++;c&&c!=k||a.ecf++;b.pageURL=""+(e.location?e.location.href:"");b.logLevel=c;b.attribution=f.attribution||b.attribution;a.erl.push({ex:f,info:b})}}function l(a,b,c,e,g){d.ueLogError({m:a,f:b,l:c,c:""+e,err:g,fromOnError:1,args:arguments},g?{attribution:g.attribution,logLevel:g.logLevel}:void 0);return!1}var k="FATAL",m="ERROR",n="WARN",p="DOWNGRADED",a={ec:0,ecf:0,
pec:0,ts:0,erl:[],ter:[],mxe:50,startTimer:function(){a.ts++;setInterval(function(){d.ue&&a.pec<a.ec&&d.uex("at");a.pec=a.ec},1E4)}};l.skipTrace=1;h.skipTrace=1;h.isStub=1;d.ueLogError=h;d.ue_err=a;e.onerror=l})(ue_csm,window);
ue.stub(ue,"event");ue.stub(ue,"onSushiUnload");ue.stub(ue,"onSushiFlush");
var ue_url='/Bear-Village%C2%AE-Billetera-Magn%C3%A9tico-Plegable/dp/B0834Z8V2V/ref=sr_1_8/uedata/unsticky/262-7660088-5537506/NoPageType/ntpoffrw',
ue_sid='262-7660088-5537506',
ue_mid='A1RKKUPIHCS9HS',
ue_sn='www.amazon.es',
ue_furl='fls-eu.amazon.es',
ue_surl='https://unagi-eu.amazon.com/1/events/com.amazon.csm.nexusclient.prod',
ue_navtiming=1,
ue_fcsn=1,
ue_isrw=true,
ue_fpf='//fls-eu.amazon.es/1/batch/1/OP/A1RKKUPIHCS9HS:262-7660088-5537506:3K2TJQ58BVNQN3K7EHVJ$uedata=s:',
ue_qsl=2000,
iOS ответ (Консоль. log):
console.log ('Full HTML:' + htmlString) первые 30 строк :
<!DOCTYPE html>
<html dir=ltr >
<head>
<title>Bear Village┬« Funda para Samsung Galaxy S9 Plus, Billetera Carcasa de Cuero con TPU Tapa Interna, Cierre Magn├®tico, Soporte Plegable, Azul:Amazon</title>
<link rel="canonical" href="https://www.amazon.es/Bear-Village%C2%AE-Billetera-Magn%C3%A9tico-Plegable/dp/B0834Z8V2V" />
<meta content="Bear Village┬« Funda para Samsung Galaxy S9 Plus, Billetera Carcasa de Cuero con TPU Tapa Interna, Cierre Magn├®tico, Soporte Plegable, Azul,Bear Village" name="keywords" /><meta content="Amazon Bear Village┬« Funda para Samsung Galaxy S9 Plus, Billetera Carcasa de Cuero con TPU Tapa Interna, Cierre Magn├®tico, Soporte Plegable, Azul" name="description" />
</head>
<body>
<a name="top"></a>
<center>Amazon.es</center>
<b id="product-title">Bear Village┬« Funda para Samsung Galaxy S9 Plus, Billetera Carcasa de Cuero con TPU Tapa Interna, Cierre Magn├®tico, Soporte Plegable, Azul</b>
<br />
<center>
<a href="/gp/aw/d/B0834Z8V2V/ref=mw_dp_img?is=m&qid=1579629120&sr=1-8&vs=1"><img src="https://images-na.ssl-images-amazon.com/images/I/71FVhkVbb1L._SL110_.jpg" width="110" id="detailImg" height="110" border="0" /></a>
<br />
<font size="-1">
<a href="/gp/aw/d/B0834Z8V2V/ref=mw_dp_img_2?in=2&qid=1579629120&sr=1-8&vs=1">Más imágenes</a>
</font>
</center>
<form method="post"
id="addToCart8"
action="/gp/aw/c/ref=mw_dp_buy_pre"
class="a-nostyle button-form">
<input type="hidden" name="a" value="B0834Z8V2V" /><input type="hidden" name="o" value="add" /><input type="hidden" name="oid" value="cBUmTruT542F5hkooRpkmtAVtdu3nKf5%2B1E%2BL4odyuwVf3sPoVEX2B1z9QZMxup6GU1URiR4yogV7Zb8zow0r9EWiLbaWYclqxMECJLW9hRrg38qlbpYuIs7KCpKNs%2FAV3IEndaiNnJC%2BUSwIBtYaITk8udEksGz" /><input type="hidden" name="qid" value="1579629120" /><input type="hidden" name="sr" value="1-8" /><input type="hidden" name="verificationSessionID" value="258-0382502-3749862" />
<center>
<input
name="addToCart"
class="cartButton"
type="submit"
value="A├▒adir preventa a la cesta"