问题
How do I change the browser used by the view(response) command in the scrapy shell? It defaults to safari on my machine but I'd like it to use chrome as the development tools in chrome are better.
回答1:
As eLRuLL already mentioned, view(response)
uses webbrowser
to open the web page you downloaded. To change its behavior, you need to set a BROWSER
environment variable.
You could do this by adding the following line at the end of your ~/.bashrc
file:
export BROWSER=/usr/bin/firefox
(if you would like firefox to be used).
I don't have Chrome installed, but by doing a fast search on Google, it seems its path is /usr/bin/google-chrome-stable
; therefore, you could try export BROWSER=/usr/bin/google-chrome-stable
instead. I didn't test it for Chrome though.
回答2:
There is no current way to specify which browser to use to open the response, as it internally uses the webbrowser package. This package uses your default configured browser to open the current response.
You could always change the default browser to chrome on your system, that should make webbrowser
use it.
回答3:
This fixed it for me: If you're on windows 10, find or create a random html-file on your system.
- Right click the html-file
- Open with
- Choose another app
- Select your browser (e.g Google Chrome) and check the box "Always use this app to open .html"
Now attempt to use view(response) in the Scrapy shell again and it should work.
来源:https://stackoverflow.com/questions/43299688/how-do-i-change-the-browser-used-by-the-scrapy-view-command