python - 自动化 Boring Stuff Lucky 批处理文件和命令行问题
问题描述
我对项目有很大的问题:“我感觉很幸运”来自用 Python 自动化无聊的东西的谷歌搜索,我搜索了几个小时的答案,但我无法处理 bat 文件问题。到目前为止,我有这样的事情:
#! python
import sys, webbrowser, bs4, requests
headers = {'User-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ 83.0.4103.61 Safari/537.36'}
link = 'https://www.google.pl/search?q=' + ' '.join(sys.argv[1:]
res = requests.get(link, headers=headers)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'lxml')
links = soup.select(".r > a[href]")
for i in range(3):
webbrowser.open(links[i].attrs['href'])
当我尝试通过 PyCharm 使用其他链接(例如下面的示例)运行它时,没关系,来自谷歌搜索的 3 个新标签正在打开搜索“python”
res = requests.get('https://www.google.pl/search?q=python', headers=headers)
但问题是我无法通过命令行通过 .bat 文件使用一些参数打开它,当我尝试通过双击打开它时它甚至无法打开(当然,当上面的测试示例在我的文件中时)。
任何人都可以帮忙吗?我的 .bat 文件如下所示:
"C:\something\something\python.exe" "D:\something\something\luckysearch.py" %1
解决方案
推荐阅读
- javascript - mapper.js 仅适用于重新加载...有点
- abap - 获取 /AIF/ERR 变体的值
- git - 如何修复远程:找不到存储库错误?
- elasticsearch - 如何使用无痛脚本访问 Elastisearch 中范围数据类型的数据
- r - 如何将可编辑的行和列以交互方式插入(和删除)到使用 R Shiny 中的 DT 包呈现的数据表中?
- python - 使用 pandas Data-frame 进行回测后如何在 Binance Futures 中执行交易
- postgresql - Postgres条件dense_rank()计算工作日数
- html - Angular > 过滤器方法的单元测试
- google-chrome - 为什么 Chrome 将 input[type=submit] 视为只读?(不再工作)
- sql - timescaledb/postgres 中基于时间的分组窗口函数