小编mir*_*lol的帖子

listdir不能正确打印非英文字母

在Python 2.7上,

for dir in os.listdir("E:/Library/Documents/Old - Archives/Case"):
   print dir
Run Code Online (Sandbox Code Playgroud)

打印出来:

Danny.xlsx
Dannyh.xlsx
~$??? ?? ?????? ??? ???? ???????.docx
Run Code Online (Sandbox Code Playgroud)

而这个:

# using a unicode literal
for dir in os.listdir(u"E:/Library/Documents/Old - Archives/Case"):
   print dir
Run Code Online (Sandbox Code Playgroud)

打印出来:

Dan.xlsx
Dann.xlsx

Traceback (most recent call last):
  File "E:\...\FirstModule.py", line 31, in <module>
    print dir
  File "C:\Python27\lib\encodings\cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2-4: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)

该文件的名称是希伯来语,因此: ?????.xls

我怎么能用Python在希伯来语中出现呢?

python unicode python-2.x

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

Scrapy:html xpath选择器返回结果为html?

如何检索标记中包含的所有HTML?

hxs = HtmlXPathSelector(response)
element = hxs.select('//span[@class="title"]/')
Run Code Online (Sandbox Code Playgroud)

编辑:如果我查看文档,我只看到返回新的xpathselectorlist的方法,或只返回标记内的原始文本.我想要检索不是新列表或文本,而是检索标记内的源代码HTML.例如:

hxs.select('//span[@class="title"]/html()')
Run Code Online (Sandbox Code Playgroud)

我想做一个像这样的方法XPathSelectorList,shal返回它里面的HTML,像这样:

<html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="leexample">
            justtext
            <p class="ihatelookingforfeatures">
                sometext
            </p>
            <p class="yahc">
                sometext
            </p>
        </div>
        <div id="lenot">
            blabla
        </div>
    an awfuly long example for this.
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我希望我清除了围绕我的问题的模棱两可.

如何从Scrapy中的HtmlXPathSelector获取HTML?(也许解决方案外部scrapy的范围?)

python xpath scrapy

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

我的Eclipse项目中意外删除了JRE

我已经开了一个新的Java项目,写了很多代码,添加了几个外部jar.我想删除一个外部jar,意外删除了JRE库.

无法弄清楚如何将JRE重新添加到项目中.

java eclipse project

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

Chrome扩展程序:在所有Google域和特定页面上运行

我希望我的内容脚本能够匹配所有谷歌域名和特定页面.我知道这是不可能的.

的manifest.json

"content_scripts": [{
        "matches": [
           ,"*://www.google.*"
           ,"*://www.youtube.com/*"
           ,"*://readthedocs.org/*"]
       ,
       ....
Run Code Online (Sandbox Code Playgroud)

还有另一种方法吗?只是想在我列出Google所有域名之前确定:)

google-chrome match google-chrome-extension content-script

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