小编Jos*_*hua的帖子

使用 Python 在 youtube 中搜索打开第一个视频

我尝试了这个,但不知道如何打开第一个视频。此代码在浏览器中打开搜索。

import webbrowser

def findYT(search):
    words = search.split()

    link = "http://www.youtube.com/results?search_query="

    for i in words:
        link += i + "+"

    time.sleep(1)
    webbrowser.open_new(link[:-1])
Run Code Online (Sandbox Code Playgroud)

这样就成功搜索到视频了,但是如何打开第一个结果呢?

python youtube beautifulsoup python-3.x

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

pip install mysqlclient with Python 3.8 不起作用

我有一个使用 Python 3.8 的 django 项目,我尝试通过以下命令安装mysqlclient库:pip install mysqlclient我收到这个错误:

MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
Run Code Online (Sandbox Code Playgroud)
  1. 我尝试使用来自何处的轮子文件进行安装(我尝试了此站点上的每个轮子),但出现错误:*...is not a supported wheel on this platform.*
  2. 我尝试从源代码安装它,但是当我运行此命令时python setup.py install,出现相同的错误:
  MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with …
Run Code Online (Sandbox Code Playgroud)

python mysql django pip

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

在不导入库和使用集合的情况下删除列表中重复项的最快方法

我试图使用以下代码从列表中删除重复项:

a = [1,2,3,4,2,6,1,1,5,2]
res = []
[res.append(i) for i in a if i not in res]
Run Code Online (Sandbox Code Playgroud)

但是我想这样做而不将我想要的列表定义为一个空列表(即省略该行res = []),例如:

a = [1,2,3,4,2,6,1,1,5,2]
#Either:
res = [i for i in a if i not in res]
#Or:
[i for i in a if i not in 'this list'] # this list is not a string. I meant it as the list being comprehensed
Run Code Online (Sandbox Code Playgroud)

我想避免图书馆进口和 set()

python list duplicates

3
推荐指数
2
解决办法
191
查看次数

Python/Json AttributeError:部分初始化的模块“json”没有属性

我正在使用 MS Code Python 3.7 运行 Windows 10

我从简单的代码块中收到以下消息

回溯(最近一次调用最后一次):
文件“c:/Users/marke/OneDrive/Desktop/Python Tutorial/json.py”,第 1 行,模块导入 json 文件“c:\Users\marke\OneDrive\Desktop\Python Tutorial\json.py”,第 6 行,在 jsText = json.loads(FileText) AttributeError: 部分初始化的模块“json”没有属性“loads”(很可能是由于循环导入)

我的代码

import json

jsFile = open("myjson.json","r")

FileText = jsFile.read
jsText = json.loads(FileText)
Run Code Online (Sandbox Code Playgroud)

python json

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

如何处理 requests.exceptions.InvalidURL:在 python 中解析失败?

我是python的新用户。我不知道为什么,但请求总是抛出 InvalidURL 异常:

>>> import requests
>>> r = requests.get('https://www.google.es/')
Run Code Online (Sandbox Code Playgroud)

输出:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 380, in prepare_url
    scheme, auth, host, port, path, query, fragment = parse_url(url)
  File "/usr/lib/python3/dist-packages/urllib3/util/url.py", line 392, in parse_url
    return six.raise_from(LocationParseError(source_url), None)
  File "<string>", line 3, in raise_from
urllib3.exceptions.LocationParseError: Failed to parse: https://www.google.es/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/requests/api.py", line 76, in get
    return request('get', url, …
Run Code Online (Sandbox Code Playgroud)

python python-requests python-3.7

0
推荐指数
1
解决办法
3305
查看次数