如何在 React 中抓取 DuckDuckGo 搜索引擎结果

问题描述

我可以在我的 react.js 项目中从 https://api.duckduckgo.com/ 获取 DuckDuckGo搜索结果。但由于它给我们仅即时答案结果,我无法获得完整的搜索结果

这是我得到搜索结果代码

import React,{ Component } from 'react';
import { render } from 'react-dom';
import axios from 'axios';

interface AppProps { }
interface AppState {
  name: string;
}

class App extends Component<AppProps,AppState> {
  constructor(props) {
    super(props);
    this.state = {
      name: 'React',query: '',img: "",};
  }

  search = () => {
    const options = {
      method: 'GET',url: 'https://api.duckduckgo.com/',params: {
        q: this.state.query,no_redirect: '1',no_html: '1',skip_disambig: '1',format: 'json'
      },};

    axios.request(options).then((res) => {
      const b = res.data;         // Search result is not satisfied for me

      if(b.Abstract != "") {
        this.setState({
          img: b.Image
        })
      }
    }).catch(function (error) {
      console.error(error);
    });
  }

  render() {
    return (
      <div>
        <Hello name={this.state.name} />
        <p>
          Start editing to see some magic happen :)
        </p>
        <input type="text" onChange={(e) => this.setState({query: e.target.value})} />
        <button type="button" onClick={this.search.bind(this)} >Search </button>
        { this.state.img !== "" && (<img src={`https://duckduckgo.com${this.state.img}`} alt="" />) }
      </div>
    );
  }
}

render(<App />,document.getElementById('root'));

有什么方法可以获得类似于网页抓取搜索结果页面的完整结果?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...