How do I change the browser used by the scrapy view command?

吃可爱长大的小学妹 提交于 2020-07-22 05:49:06

问题


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.

  1. Right click the html-file
  2. Open with
  3. Choose another app
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!