我正在使用一个简单的脚本,该脚本在日志文件中输出当前目录的路径:
(Get-Item .).FullName | out-file "C:\windows\system32\rcwm\rc.log" -append
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下都有效。然而,看似随机,追加将导致在输出字符串中的每个字符后添加空格。我的rc.log文件将如下所示:
C:\Users\root\Desktop\2222
C : \ U s e r s \ r o o t \ D e s k t o p \ 2 2 2 2
Run Code Online (Sandbox Code Playgroud)
请注意,我如何两次输出相同的目录名,并且日志文件中的结果不同。
一旦发生这种情况,附加到日志文件中的每个后续字符串的字符之间都会有空格。
可能是什么问题?
我在中遇到了以下程序C++:
template <class T>
class Val {
protected:
T x0, x;
public:
Val(T t = 1) : x0(t), x(1) {}
T val() { return x; }
void promote() { this->promote_value(); }
};
Run Code Online (Sandbox Code Playgroud)
由于某种原因,Val<int>(4).val();即使没有方法,也可以正常工作promote_value()。我试图删除模板:
class OtherVal {
protected:
int x0, x;
public:
OtherVal (int t = 1) : x0(t), x(1) {}
int val() { return x; }
void promote() { this->promote_value(); }
};
Run Code Online (Sandbox Code Playgroud)
但是现在我得到一个错误:
错误:“类OtherVal”没有名为“ promote_value”的成员;你是说“促进”吗?
为什么会这样C++表现?
在共享他自己的屏幕之前,添加 displaySurface 不会引起用户的选项限制。我试图将这些选项限制为仅让用户选择浏览器选项卡以外的任何内容。
我尝试将 displaySurface 显式设置为 'monitor' 并且仍然显示所有选项。
async startCaptureMD() {
let captureStream = null;
var screen_constraints = {
video: {
cursor: "always",
displaySurface: "monitor"
}
};
try{
captureStream = await
navigator.mediaDevices.getDisplayMedia(screen_constraints);
}catch(err){
console.log(err.message, err.code);
}
return captureStream;
},
Run Code Online (Sandbox Code Playgroud)
预期的结果是显示“您的整个屏幕”或“应用程序窗口”而不是“Chrome 选项卡”。
我正在使用 Gson 将一组 JSON 对象解析为 POJO。然后我使用 afor-loop将每个解析的对象发送到一个方法进行处理。我似乎无法找到一种方法来遍历单个对象并获取其中包含的值。
例如:
private Double thing1;
private Double thing2;
private Dboule thing3;
private void doSomething(MyObject myObj){
...myObject contains thing1, thing2, thing3 which are each doubles.
//I want to loop through the entire object,
//grab thing1's value and do something with it, then grab thing2's value... etc.
}
Run Code Online (Sandbox Code Playgroud)
这很容易做到吗?我已经尝试了一段时间,但似乎无法让它发挥作用。我可以通过使用以下方法轻松地单独抓住它们:
myObj.thing1
Run Code Online (Sandbox Code Playgroud)
但它需要在循环中完成,因为有大量的值进来。
更新:这几乎可以工作,但它打印整个对象,然后打印单个对象值。我怎样才能让它只打印单个值而不先打印所有内容?
for(Field field : data.getClass().getDeclaredFields()){
Object value = field.get(data);
System.out.println(value);
}
Run Code Online (Sandbox Code Playgroud)
输出:
[{"accel_1":0.012,"accel_2":0.125,"accel_3":0.03,"accel_4":0.012,"accel_5":0.125,"accel_6":0.03,"accel_7":0.012,"accel_8":0.125,"accel_9":0.03,"accel_10":0.012,"accel_11":0.125,"accel_12":0.03},{"accel_1":0.18,"accel_2":0.26,"accel_3":0.05,"accel_4":0.18,"accel_5":0.26,"accel_6":0.05,"accel_7":0.18,"accel_8":0.26,"accel_9":0.05,"accel_10":0.18,"accel_11":0.26,"accel_12":0.05},{"accel_1":0.06,"accel_2":0.02,"accel_3":0.03,"accel_4":0.06,"accel_5":0.02,"accel_6":0.03,"accel_7":0.06,"accel_8":0.02,"accel_9":0.03,"accel_10":0.06,"accel_11":0.02,"accel_12":0.03}]
0.012
0.125
0.03
0.012
0.125
0.03
0.012
0.125
0.03
0.012 …Run Code Online (Sandbox Code Playgroud) 我已经在python中创建了一个脚本,以仅从遍历多个页面的网站中删除指向不同餐厅的链接。通过查看位于右上角的特定文本,我可以看到有多少链接:
显示1-30 of 18891
但是我无法手动或使用脚本来跳过此链接。该站点在每个分页中将其内容增加30。
到目前为止,我已经尝试过:
import requests
from bs4 import BeautifulSoup
link = 'https://www.yelp.com/search?find_desc=Restaurants&find_loc=New%20York%2C%20NY&start={}'
for page in range(960,1920,30): # modified the range to reproduce the issue
resp = requests.get(link.format(page),headers={"User-Agent":"Mozilla/5.0"})
print(resp.status_code,resp.url)
soup = BeautifulSoup(resp.text, "lxml")
for items in soup.select("li[class^='lemon--li__']"):
if not items.select_one("h3 > a[href^='/biz/']"):continue
lead_link = items.select_one("h3 > a[href^='/biz/']").get("href")
print(lead_link)
Run Code Online (Sandbox Code Playgroud)
上面的脚本仅从其目标页面获取链接。
我如何也可以从其他页面获得链接?
c++ ×1
encoding ×1
java ×1
javascript ×1
loops ×1
object ×1
output ×1
powershell ×1
python ×1
python-3.x ×1
string ×1
templates ×1
web-scraping ×1