weread-exporter

1
2
python -m weread_exporter -b c8a32ab0813ab7c27g0173f0 -o epub -o pdf
python -m weread_exporter -b 33332bf05cbba0333b1efb4 -o epub -o pdf

报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(weread-exporter) boa@HX weread-exporter % python -m weread_exporter -b c8a32ab0813ab7c27g0173f0 -o epub -o pdf
[2024-06-04 17:32:27,536][INFO]Exporting book c8a32ab0813ab7c27g0173f0
[2024-06-04 17:32:27,826][INFO][WeReadWebPage] Launch url https://weread.qq.com/web/bookDetail/c8a32ab0813ab7c27g0173f0
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/boa/Downloads/weread-exporter/weread_exporter/__main__.py", line 158, in <module>
main()
File "/Users/boa/Downloads/weread-exporter/weread_exporter/__main__.py", line 154, in main
loop.run_until_complete(async_main())
File "/opt/miniconda3/envs/weread-exporter/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/boa/Downloads/weread-exporter/weread_exporter/__main__.py", line 85, in async_main
await page.launch(headless=args.headless, force_login=args.force_login)
File "/Users/boa/Downloads/weread-exporter/weread_exporter/webpage.py", line 174, in launch
chrome = self._check_chrome()
^^^^^^^^^^^^^^^^^^^^
File "/Users/boa/Downloads/weread-exporter/weread_exporter/webpage.py", line 167, in _check_chrome
raise utils.ChromeNotInstalledError(
weread_exporter.utils.ChromeNotInstalledError: Please make sure `chrome` is installed, and the install path is added to PATH environment.
You can test that with `which chrome` command.
(weread-exporter) boa@HX weread-exporter % which chrome
chrome not found

现在一个python程序要依赖chrome,报错如下:

1
2
3
4
weread_exporter.utils.ChromeNotInstalledError: Please make sure `chrome` is installed, and the install path is added to PATH environment. 
You can test that with `which chrome` command.
(weread-exporter) boa@HX weread-exporter % which chrome
chrome not found

如何修改代码,使得程序可以在安装了 Microsoft Edge 的系统上运行?

修改weread_exporter/webpage.py文件,将 159 行的 chrome 改为 msedge,如下:

1
2
3
4
5
if sys.platform == "darwin":
# chrome = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
chrome = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
if os.path.isfile(chrome):
return chrome

browser path python

I have a program that uses the chrome core.

But what if the user does not have the chrome browser installed? Is there a way for us to get a list of installed browsers, such as [chrome, edge], and then choose which core to use based on the installed browsers.

Please modify the code given below to support Windows, macOS, Linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def _check_chrome(self):
path_list = os.environ["PATH"].split(";" if sys.platform == "win32" else ":")
for chrome in ("chrome", "google-chrome"):
if sys.platform == "win32":
chrome += ".exe"
for path in path_list:
if os.path.isfile(os.path.join(path, chrome)):
return chrome

if sys.platform == "darwin":
chrome = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
if os.path.isfile(chrome):
return chrome

if sys.platform == "win32":
command = "where chrome"
else:
command = "which chrome"
raise utils.ChromeNotInstalledError(
"Please make sure `chrome` is installed, and the install path is added to PATH environment. \nYou can test that with `%s` command."
% command
)

报错

1
2
no library called "cairo" was found
no library called "libcairo-2" was found