所以我一直在尝试用 pyppeteer 制作一个简单的比特币价格检查器。它的工作就像一个魅力,但每当我尝试将它实现到烧瓶时,我都会收到运行时错误。
本质上,我想构建一个 Web api 调用,每当我单击按钮时,它就会调用 webscraper 文件。
如果有人可以帮助指导我,那将不胜感激!
烧瓶服务器
import webscraper
import asyncio
from flask import Flask, redirect, url_for, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html', title="Home")
@app.route('/api/scrape', methods=['POST'])
def scrape():
webscraper.crypto_price('https://coinmarketcap.com/currencies/bitcoin/')
return redirect(url_for('index'))
if(__name__ == '__main__'):
app.run()
Run Code Online (Sandbox Code Playgroud)
Pyppeteer 文件
import asyncio
from pyppeteer import browser, launch
def write_to_file(file, text):
f = open(file, 'w')
f.write(text)
f.close
def crypto_price(link):
async def main():
browser = await launch()
page = await browser.newPage()
await page.setViewport({'width': 1920, 'height': 1080})
await …Run Code Online (Sandbox Code Playgroud) 我有一个简单的 C++ 类,它使用通用模板来存储和检索通用变量。存储它们没有问题,但返回通用变量会返回十六进制值。
有人能告诉我为什么这样做吗?
节点.h
#pragma once
#include <iostream>
template <typename T>
class Node {
private:
T data;
Node *next_node;
public:
Node(T data) {
this->data = data;
std::cout << "Node with data - " << this->data << " - has been created." << std::endl;
}
T get_data() {
return this->data;
}
void set_next_node(Node next) {
this->next_node = next;
}
Node get_next_node() {
return this->next_node;
}
};
Run Code Online (Sandbox Code Playgroud)
主程序
#include <iostream>
#include "node.h"
int main() {
Node node = new Node("Hello World"); …Run Code Online (Sandbox Code Playgroud) for some reason I keep getting a "TypeError: GridFsStorage is not a constructor" error. I have no idea why its giving me this error since I'm just following the official documentation.
Storage and upload
conn.once('open', ()=> {
gfs = Grid(conn.db, mongoose.mongo)
gfs.collection('uploads')
})
const storage = new GridFsStorage({
url: DBURI,
file: (req, file)=> {
return new Promise((resolve,reject)=> {
crypto.randomBytes(16, (err, buf)=> {
if(err) {
return reject(err)
}
const filename = buf.toString('hex') + path.extname(file.originalname);
const fileInfor = {
filename: filename,
bucketName: …Run Code Online (Sandbox Code Playgroud)