反应本机cloudcraper以捕获页面代码

时间:2019-04-02 20:44:41

标签: javascript http react-native web-scraping get

我正在尝试发出http请求以获取页面的html代码,但是该页面使用了cloudcracraper,所以我正在使用模块来执行此操作。

但是该模块无法正常工作,它似乎没有发出呼叫,或者它没有打印出任何有问题的东西。

链接:Expo

代码:

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
import * as cloudscraper from 'react-native-cloudscraper';

export default class App extends React.Component {
  componentDidMount() {
    console.log('1');
    cloudscraper
      .get('https://ilgeniodellostreaming.pw/?s=avenger')
      .then(response => response.text())
      .then(responseHtml => {
        console.log('r: ', responseHtml.substring(0, 5000));
      })
      .catch(error => {
        console.error(error);
      });
    console.log('2');
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.paragraph}>
          Change code in the editor and watch it change on your phone! Save to
          get a shareable url.
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});

0 个答案:

没有答案