我已经通过AVD管理器启动了我的模拟器,一旦它运行我点击了run app.我已经等了几分钟让我的跑步设备显示出来choose a running device但窗口始终保持空白.

我想在函数中启动一个具有特定设置(privoxy,Tor,randon用户代理...)的selenium浏览器,然后在我的代码中调用此函数.我在mybrowser.py里面创建了一个python脚本:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from fake_useragent import UserAgent
from stem import Signal
from stem.control import Controller
class MyBrowserClass:
def start_browser():
service_args = [
'--proxy=127.0.0.1:8118',
'--proxy-type= http',
]
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (UserAgent().random)
browser = webdriver.PhantomJS(service_args = service_args, desired_capabilities=dcap)
return browser
def set_new_ip():
with Controller.from_port(port=9051) as controller:
controller.authenticate(password=password)
controller.signal(Signal.NEWNYM)
Run Code Online (Sandbox Code Playgroud)
然后我将其导入到另一个脚本中myscraping.py:
import mybrowser
import time
browser= mybrowser.MyBrowserClass.start_browser()
browser.get("https://canihazip.com/s")
print(browser.page_source)
mybrowser.MyBrowserClass.set_new_ip()
time.sleep(12)
browser.get("https://canihazip.com/s")
print(browser.page_source)
Run Code Online (Sandbox Code Playgroud)
浏览器正在运行 - 我可以访问该页面并使用它进行检索.page_source.
但IP在第一次和第二次打印之间没有变化.如果我在里面移动函数的内容myscraping.py(并删除import +函数调用),那么IP就会改变. …
对于在线 pdf,我可以简单地#page=10在 url 后面添加以打开第 10 页上的 pdf。
但这不适用于本地pdf。[ 2020 编辑:这现在也适用于本地 pdf 也参见。选择的答案]
假设我file:///C:/Users/Me/Desktop/My%20Documents/textbook.pdf在 chrome 中打开这个 url 。如果我#page=10在链接末尾添加(pdf 超过 50 页),则 chrome 会返回此错误:
Your file was not found It may have been moved or deleted.
ERR_FILE_NOT_FOUNDthis url
Run Code Online (Sandbox Code Playgroud)
Chrome 还更改了 url (cf My%2520Documents): file:///C:/Users/Me/Desktop/My%2520Documents/textbook.pdf%23page=10
我有许多字符串(推文推文),当我回应它时,我想从中删除链接.
我无法控制字符串,即使所有链接都以http开头,它们也可以以"/"或";"结尾.没有,被跟踪或不被空间跟随.此外,有时链接和它之前的单词之间没有空格.
这种字符串的一个例子:
The Third Culture: The Frontline of Global Thinkinghttp://is.gd/qFioda;via @edge
Run Code Online (Sandbox Code Playgroud)
我尝试使用preg_replace,但无法提出适合所有异常的解决方案:
<?php echo preg_replace("/\http[^)]+\;/","",$feed->itemTitle); ?>
Run Code Online (Sandbox Code Playgroud)
知道我该怎么办吗?
编辑:我试过了
<?php echo preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)???)@', ' ', $feed->itemTitle); ?>
Run Code Online (Sandbox Code Playgroud)
但仍然没有成功.
编辑2:我找到了这个:
<?php echo preg_replace('^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-??\.\?\,\'\/\\\+&%\$#_]*)?$^',' ', $feed->itemTitle); ?>
Run Code Online (Sandbox Code Playgroud)
它会按预期删除链接,但当链接与其前面的单词之间没有空格时,它也会删除整个字符串.
我尝试过使用pip -m install win32api,但我仍然收到错误" 无法打开文件'pip':[Errno 2]没有这样的文件或目录"
谁可以帮我这个事?
注意:我已将python.exe文件重命名为python2和python3,因为我在我的电脑上安装了这两个版本.
我想从 gmail 下载 100 多封电子邮件的 pdf 格式。通过 gmail 中的打印选项手动下载所有内容会太长。
此 python 脚本检索所选标签中的电子邮件。我怎样才能把这封电子邮件转换成pdf文件。
# source = https://developers.google.com/gmail/api/quickstart/python?authuser=2
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
def main():
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request()) …Run Code Online (Sandbox Code Playgroud) 我正在构建一个基于 Google 翻译的开源 Chrome 扩展(此处)。
\n\n我已经阅读了有关 Google 翻译 API 的其他问题(例如这个和这个),但我仍然没有答案。\n我发现了几个 Google 翻译的网址,如下所示:
\n\n\n\n似乎所有 URL 都是 3 部分的不同组合:
\n\n基本网址:
\n\ntranslate.googleapis.com/translate_a/ https://translate.google.com/translate_a/ https://clients5.google.com/translate_a/translate_a/: 或single之后的第一个参数t
客户端可以是gtx,t或dict-chrome-ex[或者显然是任何 ID ]
到目前为止,我已经看到返回的 JSON 存在差异。\n此https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=fr&dt=t&q=father&ie=UTF-8&oe=UTF-8返回以下 json:
\n\n[[["p\xc3\xa8re","father",null,null,1]\n]\n,null,"en"]\nRun Code Online (Sandbox Code Playgroud)\n\n虽然此https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=en&tl=fr&dt=t&q=father返回此 json:
\n\n{"sentences":[{"trans":"p\xc3\xa8re","orig":"father","backend":1},{"src_translit":"\xcb\x88f\xc3\xa4T\xcd\x9fH\xc9\x99r"}],"dict":[{"pos":"noun","terms":["p\xc3\xa8re"],"entry":[{"word":"p\xc3\xa8re","reverse_translation":["father","dad","parent","papa"],"score":0.70910621,"previous_word":"le","gender":1}],"base_form":"father","pos_enum":1},{"pos":"verb","terms":["engendrer","concevoir"],"entry":[{"word":"engendrer","reverse_translation":["generate","engender","give rise to","beget","breed","father"],"synset_id":[52561],"score":0.00017133754},{"word":"concevoir","reverse_translation":["design","conceive","devise","plan","form","father"],"synset_id":[52561],"score":4.8327973e-05}],"base_form":"father","pos_enum":2}],"src":"en","alternative_translations":[{"src_phrase":"father","alternative":[{"word_postproc":"p\xc3\xa8re","score":1000,"has_preceding_space":true,"attach_to_next_token":false}],"srcunicodeoffsets":[{"begin":0,"end":6}],"raw_src_segment":"father","start_pos":0,"end_pos":0}],"confidence":1,"ld_result":{"srclangs":["en"],"srclangs_confidences":[1],"extended_srclangs":["en"]},"query_inflections":[{"written_form":"father","features":{"number":2}},{"written_form":"fathers","features":{"number":1}}],"target_inflections":[{"written_form":"p\xc3\xa8re","features":{"gender":1,"number":2}},{"written_form":"p\xc3\xa8res","features":{"gender":1,"number":1}},{"written_form":"p\xc3\xa8re","features":{"number":2}},{"written_form":"p\xc3\xa8res","features":{"number":1}}]}\nRun Code Online (Sandbox Code Playgroud)\n\n … 我想ForegroundColor使用键盘快捷键更改Google文档中的选定文本.
我可以使"更改ForegroundColor"部分(使用绑定到函数setColor()的菜单项),而不是"键盘快捷键部分".
我找到了这段代码但是我无法实现它:
$(document).keydown(function(e){
//CTRL + Q keydown combo
if(e.ctrlKey && e.keyCode == 81){
$( '#output' ).html("I've been pressed!");
}
})
Run Code Online (Sandbox Code Playgroud)
我的困难:
1)我不确定将此代码放在我的脚本编辑器中的位置(我试图将它放在onOpen()下面的函数中,但也在它上面没有成功).
2)我不确定$(文件)应该引用什么.
3)我不确定他们的意思是"必须先点击/激活侧边栏才能实现".
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Menu')
.addItem('Color', 'setColor')
.addToUi();
var document = DocumentApp.getActiveDocument() // should it be here?
$(document).keydown(function(e){
//CTRL + Q keydown combo
if(e.ctrlKey && e.keyCode == 81){
SpreadsheetApp.getUi().alert('Hello, world!');
}
})
}
function setColor1() {
var selection = DocumentApp.getActiveDocument().getSelection();
if (selection) {
var elements …Run Code Online (Sandbox Code Playgroud) 我正在使用这个 VS Code扩展,我想更改命令在上下文菜单中的显示位置。我可以通过直接修改package.json来做到这一点。例如,我在editor/context列表中添加了(大约第 100 行),这个:
{
"command": "fileutils.renameFile",
"group": "edit"
}
Run Code Online (Sandbox Code Playgroud)
它奏效了,我可以在我的上下文菜单中看到重命名命令,但是......当有更新时,我将失去我的编辑。所以我试图在 中添加这段代码,C:\Users\<user>\AppData\Roaming\Code\User\settings.json但它不起作用。
如何自定义 VS Code 扩展,尤其是editor/context命令?
使用 Gmail API,如何检索电子邮件的主题?
我在原始文件中看到它,但检索它很麻烦,我相信应该有一种方法可以直接通过 API 来完成它。
messageraw= service.users().messages().get(userId="me", id=emails["id"], format="raw", metadataHeaders=None).execute()
Run Code Online (Sandbox Code Playgroud)
这是因为这个同样的问题一个,但它已经接近甚至让我不能比发布提出了一个更好的答案。
python ×4
python-3.x ×3
gmail-api ×2
pdf ×2
android ×1
definition ×1
download ×1
email ×1
google-docs ×1
javascript ×1
jquery ×1
phantomjs ×1
php ×1
python-2.7 ×1
regex ×1
return ×1
selenium ×1
string ×1