我正在尝试使用PHP来获取项目的Steam社区市场价格.我拿一个网址(例如:http://steamcommunity.com/market/listings/730/StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29)然后我下载了内容file_get_contents().我试着用这个:
function getInnerHTML($string, $tagname, $closetagname) {
$pattern = "/<$tagname ?.*>(.*)<\/$closetagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
Run Code Online (Sandbox Code Playgroud)
运用
getInnerHTML($str, 'span class="market_listing_price market_listing_price_with_fee"', 'span');
Run Code Online (Sandbox Code Playgroud)
我可以使用file_get_contents的一个例子是:
<span class="market_table_value">
<span class="market_listing_price market_listing_price_with_fee">
$1.92 </span>
<span class="market_listing_price market_listing_price_without_fee">
$1.68 </span>
<br/>
</span>
Run Code Online (Sandbox Code Playgroud)
但它什么也没有回报.
有人有想法吗?
我已经写了一段时间的C ++代码,但是一段时间以来,我一直在想一些事情,而没有找到一个明确的答案。
我的意思是:假设我有一个函数(可以是方法,可以是static,但不一定),并且该函数使用一些“重”对象(例如无法确定的字符串)在编译时很容易,但这在整个执行过程中是恒定的)。我实际遇到的一个示例如下:
/* Returns an endpoint for an API
* Based on the main API URL (getApiUrl())
*/
virtual QString getEndPointUrl() const override
{
QString baseUrl = getApiUrl();
QString endpointUrl = QString("%1/%2").arg(baseUrl, "endpoint");
return endpointUrl;
}
Run Code Online (Sandbox Code Playgroud)
当然,这只是一个例子(我知道QStrings具有自己独特的Qt内存管理功能,但是让我们承认我们正在处理基本对象)。
执行以下操作是一个好主意吗?
virtual QString getEndPointUrl() const override
{
/* We determine baseUrl only once */
static const QString baseUrl = getApiUrl();
/* We compute endpointUrl only once */
static const QString endpointUrl = QString("%1/%2").arg(baseUrl, "endpoint");
return endpointUrl; …Run Code Online (Sandbox Code Playgroud) 我开始创建一个小应用程序来获取与Facebook ID相关联的名称以用于更大的项目.我刚刚开始使用Facebook API,它给了我奇怪的结果.大多数时候,一切都很好.我使用这个代码(我使用的是Python,但这并不重要,因为它是导致问题的Facebook API):
def downloadString(url, params):
cookie = {}
data = requests.get(url,cookies=cookie,params=params)
return data.text
url = "https://graph.facebook.com/v2.6/"
id = "afriendidhere"
dl = basics.downloadString(url + id, {"access_token":accesstoken})
res = json.loads(dl)
Run Code Online (Sandbox Code Playgroud)
正如我所说,大多数时候,它的工作正常,给我一个给定人的名字.但是,对于我朋友列表中的两个人,我收到以下消息:
{
"error": {
"message": "Unsupported get request. Object with ID 'theid' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "FTfrh78XjW/"
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么.拥有此ID的人确实存在,因为我可以访问http://facebook.com/messages/theid页面,它会向我提供此用户的对话历史记录.导致错误的人总是一样的,其他人都是完美的.
有谁知道为什么?
简单的问题:我正在尝试使用 Discord API 来备份服务器(或公会,如果您使用官方术语)上的所有消息。
所以我实现了 OAuth 没有任何问题,我有我的访问令牌,我可以查询一些端点(我尝试过/users/@me,/users/@me/guilds)。不过,大多数都不起作用。例如,如果我查询/users/@me/channels(应该是 DM),我会从 API 收到 401 未经授权的响应。如果我从中收集公会 ID /users/@me/guilds,然后尝试使用 列出其中的频道,情况也是一样的/guilds/guild.id/channels。
真正奇怪的是,我确实拥有所需的所有范围(我认为是这样,我没有采用 RPC 范围,因为我认为它不是我想做的事情所必需的),而且我自己无法弄清楚...同样奇怪的是,在 OAuth 授权屏幕上,我有这两件事:
它有点反驳自己......:(
您有什么想法想分享吗?
谢谢!
注意:我正在使用 Python,但我认为它与这里无关,因为某些端点确实可以使用我拥有的标头和令牌...
这是我的“验证码”:
baseUrl = "https://discordapp.com/api"
def authorize():
scopes = [
"guilds",
"email",
"identify",
"messages.read",
"guilds.join",
"gdm.join",
"connections"
]
urlAuthorize = "{}/oauth2/authorize?client_id={}&scope={}&response_type=code".format(baseUrl, clientid, ('+'.join(scopes)))
pyperclip.copy(urlAuthorize)
code = input("Code: ")
return code
def getAccessToken(code):
url = "{}/oauth2/token".format(baseUrl)
params = {
"client_id" : clientid,
"client_secret" : clientsecret,
"redirect_uri" …Run Code Online (Sandbox Code Playgroud) 我对 Docker 还很陌生,并试图让我的第一个(真实)镜像启动并运行。我已经写了我的 Dockerfile:
WORKDIR /myapp
VOLUME /myapp/configuration
VOLUME /etc/asterisk
VOLUME /usr/share/asterisk/sounds
Run Code Online (Sandbox Code Playgroud)
所以我的容器应该开始/myapp,我应该能够安装外部卷来配置我的应用程序 ( configuration)、Asterisk 及其声音。
但是,当我使用我的图像启动容器时:
docker run -it \
--entrypoint /bin/bash myapp \
-v $(pwd)/asterisk:/etc/asterisk \
-v $(pwd)/configuration:/myapp/configuration \
-v $(pwd)/asterisk/sounds:/usr/share/asterisk/sounds
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
/bin/bash: /home/me/Docker/asterisk:/etc/asterisk: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么。我已经证实这不是行尾问题(CRLF而不是LF例如预期的问题),但事实并非如此。我真的不知道。
如果算的话,我正在运行基本的 OS Loki。
请建议。
我正在尝试发现C ++中的异步编程。这是我一直在使用的玩具示例:
#include <iostream>
#include <future>
#include <vector>
#include <chrono>
#include <thread>
#include <random>
// For simplicity
using namespace std;
int called_from_async(int m, int n)
{
this_thread::sleep_for(chrono::milliseconds(rand() % 1000));
return m * n;
}
void test()
{
int m = 12;
int n = 42;
vector<future<int>> results;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
results.push_back(async(launch::async, called_from_async, i, j));
}
}
for(auto& f : results)
{
cout << f.get() << …Run Code Online (Sandbox Code Playgroud) 简单的问题:给一个字符串
string = "Word1 Word2 Word3 ... WordN"
Run Code Online (Sandbox Code Playgroud)
是否有一种pythonic方式来做到这一点?
firstWord = string.split(" ")[0]
otherWords = string.split(" ")[1:]
Run Code Online (Sandbox Code Playgroud)
像打包一样?
谢谢
我是C++的新手,我正在std::cout用于调试目的.
虽然,我真的希望能够使用cout而不是整个std::cout事情.我知道我可以导入std名称空间,但我已经解释过,由于名称冲突可能会因此导致这是一件坏事.
反正有没有这样做?
我试过了
std::ostream cout = std::cout;
但我明白了
function "std::basic_ostream<_CharT, _Traits>::basic_ostream(const std::basic_ostream<_CharT, _Traits> &) [with _CharT=char, _Traits=std::char_traits<char>]" (declared at line 391 of "/usr/include/c++/5/ostream") cannot be referenced -- it is a deleted function
请建议.
我目前正在使用 LLVM 构建 JIT。structs我希望能够在我的 JIT IR 中使用一些 C 语言。其中之一具有以下布局:
struct myStruct {
int depth;
myStruct* parent;
}
Run Code Online (Sandbox Code Playgroud)
当使用 进行编译clang和使用时-S -emit-llvm,我得到以下结果,这似乎绝对合理:
type myStruct = { i32, myStruct* }
Run Code Online (Sandbox Code Playgroud)
好吧。现在,如果我想使用 LLVM API 执行相同的操作,我不太确定应该如何执行。以下(预期)不起作用:
auto intType = IntegerType::get(context, 32); // 32 bits integer
Type* myStructPtrType = nullptr; // Pointer to myStruct
// The following crashes because myStructPtrType is null:
auto myStructType = StructType::create(context, { intType, myStructPtrType }, "myStruct"); // myStruct
myStructPtrType = PointerType::get(myStructType, 0); // Initialise the …Run Code Online (Sandbox Code Playgroud) 为了为我的 Python 代码编写自定义文档生成器,我想编写一个能够匹配以下内容的正则表达式:
def my_function(arg1,arg2,arg3):
"""
DOC
"""
Run Code Online (Sandbox Code Playgroud)
我当前的问题是,使用以下正则表达式:
def (.+)\((?:(\w+),)*(\w+)\)
Run Code Online (Sandbox Code Playgroud)
我只能匹配my_function, arg2and arg3(根据 Pythex.org)。
我不明白我做错了什么,因为我(?:(\w+),)*应该匹配尽可能多的参数,直到最后一个(此处arg3)。有人能解释一下吗?
谢谢
我正在尝试使用 Flask 和 Google Datastore 创建一个基本的 Web 应用程序,以便让自己使用 Google Cloud。但是,当我部署我的应用程序时,我收到错误 500,详细信息是 Python 无法导入 Datastore : ImportError: No module named cloud。
这是我的app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: .*
script: main.app
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
- name: flask
version: 0.12
Run Code Online (Sandbox Code Playgroud)
我的main.py开始如下:
from __future__ import absolute_import
# Standard imports
import time
import logging
import json
import threading
# Flask framework
from flask import request
from flask import …Run Code Online (Sandbox Code Playgroud) python ×4
c++ ×3
regex ×2
api ×1
asynchronous ×1
cout ×1
discord ×1
docker ×1
facebook ×1
llvm ×1
llvm-c++-api ×1
oauth ×1
performance ×1
php ×1
python-3.x ×1
steam ×1