小编Ech*_*yak的帖子

在Pycharm中使用Anaconda解释器清空可用的包

我使用Python 2.7.13在我的Windows 7 64位中安装了Anaconda.

我通过在anaconda安装目录中找到python.exe来在我的Python中设置解释器.

我可以运行程序.但是,我无法使用Pycharm的软件包安装程序安装其他软件包. 在此输入图像描述

我看过在线指南,但到目前为止没有任何帮助.我究竟做错了什么?

编辑:我使用管理器存储库按钮添加了链接https://pypi.python.org/simple. 在此输入图像描述

但是,它不起作用

python pycharm anaconda

11
推荐指数
1
解决办法
5198
查看次数

在xpath中使用Starts with和end函数查找具有selenium的元素

我试图从这个输入链接描述中提取所有那些类名称适合正则表达式模式frag-0-0,frag-1-0等的标签

我正在尝试以下代码

driver = webdriver.PhantomJS()
    for frg in frgs:
        driver.get(URL + frg[1:])
        frags=driver.find_elements_by_xpath("//*[starts-with(@id, 'frag-') and ends-with(@id, '-0')]")
    for frag in frags:
            for tag in frag.find_elements_by_css_selector('[class^=fragmark]'):
                lst.append([tag.get_attribute('class'), tag.text])
    driver.quit()
Run Code Online (Sandbox Code Playgroud)

这是我的追溯:

回溯(最近通话最后一个):文件"/home/ubuntu/workspace/vroniplag/vroni.py",线路116,在OP( 'AAF')文件"/home/ubuntu/workspace/vroniplag/vroni.py"线101,在运算plags = getplags(CD)文件"/home/ubuntu/workspace/vroniplag/vroni.py",线92,在getplags断支= driver.find_elements_by_xpath("// [开始-与(@id,' frag-')和ends-with(@ id,' - 0')]")文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",第305行在find_elements_by_xpath返回self.find_elements(由= By.XPATH,值= xpath的)文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",线路778,在find_elements '值':值})[ '值']文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",线路236,在执行self.error_handler. check_response(响应)文件"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",线192,在check_response加注exception_class(消息,屏幕,堆栈跟踪)硒.common.exceptions.InvalidSelectorException:消息:错误消息=>'无法找到带有xpath表达式的元素// [starts-with(@ id,'frag-')和ends-with(@id,' - 0') ]由于以下错误:错误:INVALID_EXPRESSION_ERR:由Request => {"headers"引起的DOM XPath异常51:{"接受":"application/json","Accept-Encoding":"identity","Connection" : "关闭", "内容长度": "139", "内容类型": "应用/ JSON;字符集= UTF-8", "主机": "127.0.0.1:45340","User-Agent" :"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"using \":\"xpath \",\"sessionId \": \"0dbc6ad0-4352-11e6-8cb8-4faebd646180 \",\"value \":\"//*[开头 - (@id,'frag-')和结尾(@id,' - 0' )]\"}", "URL": "/元件", "urlParsed":{ "锚": …

python selenium xpath

6
推荐指数
1
解决办法
5417
查看次数

在Python 3中的地图中调用none

我在Python2.7中执行以下操作:

>>> a = [1,2,3,4,5]
>>> b = [2,1,3,4]
>>> c = [3,4]
>>> map(None, a, b, c)
[(1, 2, 3), (2, 1, 4), (3, 3, None), (4, 4, None), (5, None, None)]
Run Code Online (Sandbox Code Playgroud)

我试图在Python3中做类似的事情

>>> a = [1,2,3,4,5]
>>> b = [2,1,3,4]
>>> c = [3,4]
>>> map(None, a, b, c)
<map object at 0xb72289ec>
>>> for i,j,k in map(None, a, b, c):
...  print (i,j,k)
... 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x map-function

5
推荐指数
1
解决办法
1814
查看次数

梵文的音节化

我正在尝试对梵文词进行音节化

धर्मक्षेत्रे - >धर्मक्षेत्रेdharmakeshetre - > DHAR麦SHET重

wd.split('?')
Run Code Online (Sandbox Code Playgroud)

我得到的结果如下:

['??', '??', '???', '??']
Run Code Online (Sandbox Code Playgroud)

哪个部分正确

我尝试另一个词कुरुक्षेत्र - >कुरुक्षेत्रेkurukshetre - >区鲁格她唱到tre

['?????', '???', '??']
Run Code Online (Sandbox Code Playgroud)

结果显然是错误的.

如何有效地提取音节?

python string utf python-3.x devanagari

5
推荐指数
1
解决办法
263
查看次数

使用 Python 中的 smtp 发送电子邮件时发生 SSL 错误

我想使用 Outlook 发送电子邮件。代码如下:

import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg['From'] = '*******'
msg['Subject'] = 'Some subject here'
msg['To'] = '********'
        
msg.set_content('Some text here')

with smtplib.SMTP_SSL('smtp-mail.outlook.com', 587) as smtp:
    smtp.login('******', '****')
    smtp.send_message(msg)
    print('Email sent!')
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

---------------------------------------------------------------------------
SSLError                                  Traceback (most recent call last)
<ipython-input-8-4d5956f55c88> in <module>
      6 msg.set_content('Some text here')
      7 
----> 8 with smtplib.SMTP_SSL('smtp-mail.outlook.com', 587) as smtp:
      9     smtp.login('sender_email', 'password')
     10     smtp.send_message(msg)

~/anaconda/envs/quant2/lib/python3.6/smtplib.py in __init__(self, host, port, local_hostname, keyfile, certfile, timeout, source_address, context)
   1029             self.context = context
   1030 …
Run Code Online (Sandbox Code Playgroud)

outlook smtp python-3.x

5
推荐指数
1
解决办法
4936
查看次数

在c9中运行硒

我正在尝试运行使用selenium模块的python代码.这段代码在我的PC中使用了一个chromedriver完美运行.我试图在c9.io中运行它.我下载了chromedriver 64位版本,并使用chmod授予777权限.我仍然无法让它发挥作用

但是,我收到以下错误:

Traceback (most recent call last):
  File "/home/ubuntu/workspace/vroniplag/vroni.py", line 119, in <module>
    op('Aaf')
  File "/home/ubuntu/workspace/vroniplag/vroni.py", line 104, in op
    plags=getplags(cd)
  File "/home/ubuntu/workspace/vroniplag/vroni.py", line 92, in getplags
    driver = webdriver.Chrome(chromedriver)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 86, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 99, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service ./chromedriver unexpectedly exited. Status code was: 127
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我如何解决这个问题

python selenium c9.io

4
推荐指数
1
解决办法
3709
查看次数

使用countif中的通配符查找数字字符

我有一个countif函数,使用它我想要计算那些在任何地方都有数字字符的单元格.

Column A
Rich-Dilg-street 3
I have 4 apples
I have seven dogs
Run Code Online (Sandbox Code Playgroud)

如何countif使用通配符编写标准,以便我可以计算具有数字字符的标准?在上面的例子中,答案应该是2(1和2不是3)

excel excel-formula

4
推荐指数
1
解决办法
723
查看次数

如果用户未使用 FastAPI-Login 包登录,则重定向到登录页面

我想在用户未登录时将他们重定向到登录页面。

这是我的代码:

from fastapi import (
    Depends,
    FastAPI,
    HTTPException,
    status,
    Body,
    Request
)
from fastapi.encoders import jsonable_encoder
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from fastapi.responses import HTMLResponse, RedirectResponse
import app.models as models
import app.database as database
from datetime import datetime, timedelta
from jose import JWTError, jwt
from starlette.responses import FileResponse
from fastapi_login import LoginManager
from fastapi_login.exceptions import InvalidCredentialsException
from fastapi import Cookie
import re

app = FastAPI()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
manager = LoginManager(SECRET_KEY, token_url="/auth/login", use_cookie=True)
manager.cookie_name = "token"


@app.get("/")
@app.get("/item")
async …
Run Code Online (Sandbox Code Playgroud)

python fastapi

4
推荐指数
1
解决办法
4212
查看次数

正则表达式在 bs4 中不起作用

我正在尝试从 watchseriesfree.to 网站上的特定文件主机中提取一些链接。在以下情况下,我想要rapidvideo 链接,所以我使用regex 过滤掉那些带有包含rapidvideo 的文本的标签

import re
import urllib2
from bs4 import BeautifulSoup

def gethtml(link):
    req = urllib2.Request(link, headers={'User-Agent': "Magic Browser"})
    con = urllib2.urlopen(req)
    html = con.read()
    return html


def findLatest():
    url = "https://watchseriesfree.to/serie/Madam-Secretary"
    head = "https://watchseriesfree.to"

    soup = BeautifulSoup(gethtml(url), 'html.parser')
    latep = soup.find("a", title=re.compile('Latest Episode'))

    soup = BeautifulSoup(gethtml(head + latep['href']), 'html.parser')
    firstVod = soup.findAll("tr",text=re.compile('rapidvideo'))

    return firstVod

print(findLatest())
Run Code Online (Sandbox Code Playgroud)

但是,上面的代码返回一个空白列表。我究竟做错了什么?

python regex urllib2 bs4

3
推荐指数
1
解决办法
542
查看次数

按日期排序哈希映射

这是我的json:

[
{"name": "John Smith","date":"2017-02-02T23:07:09Z","id":"1223234"}
{"name": "John Doe","date":"2015-07-03T21:05:10Z","id":"3242342"},
{"name": "Jane Fan","date":"2016-12-22T13:27:19Z","id":"2123444"}
]
Run Code Online (Sandbox Code Playgroud)

我已将上面的内容转换为hashmap.现在我想对日期值进行排序.

是否有内置功能可以帮助我实现这一目标?例如,用Python排序

java sorting hashmap

2
推荐指数
1
解决办法
302
查看次数