我目前正在使用Beautiful Soup来解析HTML文件并调用get_text(),但似乎我留下了很多\xa0 Unicode表示空格。在python2.7中是否有一种有效的方法将它们全部删除,并将它们更改为空格?我想更普遍的问题应该是,有没有办法移除Unicode格式?

我尝试使用:line = line。replace(u'\xa0',' '),正如另一个线程所建议的那样,但这将\xa0改为u,所以现在我到处都是“u”。):

编辑:这个问题似乎可以通过str.replace(u'\xa0', ' ').encode('utf-8')来解决,但是仅仅使用.encode('utf-8')而不使用replace()似乎会导致它吐出更奇怪的字符,例如\xc2。有人能解释一下吗?

我正在使用Requests: HTTP for Humans库,我得到了这个奇怪的错误,我不知道这是什么意思。

No connection adapters were found for '192.168.1.61:8080/api/call'

有人知道吗?

我安装了最新版本的Python(3.6.4 64位)和最新版本的PyCharm(2017.3.3 64位)。然后我在PyCharm (Numpy, Pandas等)中安装了一些模块,但当我尝试安装Tensorflow时,它没有安装,我得到了错误消息:

无法找到一个满足需求的版本 没有找到匹配的TensorFlow分布。

然后我尝试从命令提示符安装TensorFlow,我得到了同样的错误消息。 不过,我确实成功安装了tflearn。

我也安装了Python 2.7,但我再次得到相同的错误消息。我在谷歌上搜索了这个错误,并尝试了一些建议给其他人的东西,但都不起作用(这包括安装Flask)。

如何安装Tensorflow?谢谢。

我有一个。txt文件的值。

这些值如下所示:

Value1
Value2
Value3
Value4

我的目标是将值放在一个列表中。当我这样做时,列表看起来像这样:

['Value1\n', 'Value2\n', .〕

\n不需要。

这是我的代码:

t = open('filename.txt')
contents = t.readlines()

我正在使用Nginx和Gunicorn配置Django项目。

当我进入gunicorn端口时。在Nginx服务器中,我在错误日志文件中得到以下错误;

2014/05/30 11:59:42 [crit] 4075#0: *6 connect()到127.0.0.1:8001失败(13:权限被拒绝)而连接到上游,客户端:127.0.0.1,服务器:localhost,请求:“GET / HTTP/1.1”,上游:“http://127.0.0.1:8001/”,主机:“localhost:8080”

下面是我的nginx.conf文件的内容;

server {
    listen 8080;
    server_name localhost;
    access_log  /var/log/nginx/example.log;
    error_log /var/log/nginx/example.error.log;

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
    }
}

在HTML页面中,我得到502坏网关。

我犯了什么错误?

我正在尝试使用命令安装PIL (Python映像库):

sudo pip install pil

但我得到了以下信息:

Downloading/unpacking PIL
  You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
  Downloading PIL-1.1.7.tar.gz (506kB): 506kB downloaded
  Running setup.py egg_info for package PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    
Installing collected packages: PIL
  Running setup.py install for PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    --- using frameworks at /System/Library/Frameworks
    building '_imaging' extension
    clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -IlibImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o
    unable to execute clang: No such file or directory
    error: command 'clang' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/private/tmp/pip_build_root/PIL/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AYrxVD-record/install-record.txt --single-version-externally-managed:
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py

running install

running build

.
.
.
.

copying PIL/XVThumbImagePlugin.py -> build/lib.macosx-10.8-intel-2.7

running build_ext

--- using frameworks at /System/Library/Frameworks

building '_imaging' extension

creating build/temp.macosx-10.8-intel-2.7

creating build/temp.macosx-10.8-intel-2.7/libImaging

clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -IlibImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o

unable to execute clang: No such file or directory

error: command 'clang' failed with exit status 1

----------------------------------------
Cleaning up…

你能帮我安装PIL吗?

是否有其他方法在给定键存在的情况下删除字典中的项,除了:

if key in mydict:
    del mydict[key]

这个场景是,我得到了一个键的集合,要从给定的字典中删除,但我不确定它们是否都存在于字典中。以防我错过了更有效的方法。

...
soup = BeautifulSoup(html, "lxml")
File "/Library/Python/2.7/site-packages/bs4/__init__.py", line 152, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

以上输出在我的终端上。我使用的是Mac OS 10.7.x。我有Python 2.7.1,并遵循本教程获得了Beautiful Soup和lxml,它们都成功安装了,并与位于这里的单独测试文件一起工作。在导致此错误的Python脚本中,我包含了这一行: 导入comparePages 在pageCrawler文件中,我包含了以下两行代码: 从bs4导入BeautifulSoup 从urllib2导入urlopen

任何帮助找出问题是什么以及如何解决都将不胜感激。

我一直在为工作中的简单任务编写Python脚本,从未真正费心将它们打包供他人使用。现在我被指派为REST API制作Python包装器。我完全不知道如何开始,我需要帮助。

我有什么:

(只是想尽可能具体)我已经准备好了virtualenv,它也在github上,python的.gitignore文件也在那里,另外,与REST API交互的请求库。就是这样。

这是当前目录树

.
├── bin
│   └── /the usual stuff/
├── include
│   └── /the usual stuff/
├── lib
│   └── python2.7
│       └── /the usual stuff/
├── local
│   └── /the usual stuff/
└── README.md

27 directories, 280 files

我甚至不知道该把。py文件放在哪里,如果我要创建的话。

我想做的是:

使用"pip install…"使python模块可安装

如果可能的话,我想要一个关于编写Python模块的通用步骤。

我得到以下错误:

Exception in thread Thread-3:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in        __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in  run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Matthew/Desktop/Skypebot 2.0/bot.py", line 271, in process
info = urllib2.urlopen(req).read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>

下面是导致这个错误的代码:

if input.startswith("!web"):
    input = input.replace("!web ", "")      
    url = "https://domainsearch.p.mashape.com/index.php?name=" + input
    req = urllib2.Request(url, headers={ 'X-Mashape-Key': 'XXXXXXXXXXXXXXXXXXXX' })
    info = urllib2.urlopen(req).read()
    Message.Chat.SendMessage ("" + info)

我正在使用的API要求我使用HTTPS。我怎样才能让它绕过验证呢?