Python 如何将Google Chrome扩展与Selenium结合使用?
我正试图从类似这样的页面中获取匹配信息(页面的格式相同,但对于不同的匹配显然有不同的值): 问题是,我想要的信息只有在您使用Chrome扩展名“Lounge Destroyer”时才会显示。。。经过无数次的尝试和错误,我最终发现为了获得这些信息,我使用的python脚本必须以某种方式“包含在其中”扩展。我在这里浏览了其他答案,并从不同的stackoverflow线程中找到了这段代码,该线程演示了如何在使用selenium时添加扩展:Python 如何将Google Chrome扩展与Selenium结合使用?,python,google-chrome,selenium,google-chrome-extension,web-scraping,Python,Google Chrome,Selenium,Google Chrome Extension,Web Scraping,我正试图从类似这样的页面中获取匹配信息(页面的格式相同,但对于不同的匹配显然有不同的值): 问题是,我想要的信息只有在您使用Chrome扩展名“Lounge Destroyer”时才会显示。。。经过无数次的尝试和错误,我最终发现为了获得这些信息,我使用的python脚本必须以某种方式“包含在其中”扩展。我在这里浏览了其他答案,并从不同的stackoverflow线程中找到了这段代码,该线程演示了如何在使用selenium时添加扩展: from selenium impor
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chop = webdriver.ChromeOptions()
chop.add_extension('Adblock-Plus_v1.4.1.crx')
driver = webdriver.Chrome(chrome_options = chop)
我找到了LoungeDestroyer的.crx文件,将其放在chrome扩展文件夹中(从“Get Info”获取文件地址),并对上述代码进行了一些修改,以获得以下内容:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chop = webdriver.ChromeOptions()
chop.add_extension('Users/Username_Here/Library/Application Support/Google/Chrome/Default/Extensions/ghahcnmfjfckcedfajbhekgknjdplfcl/LoungeDestroyer_v0.9.3.7.crx')
driver = webdriver.Chrome(chrome_options = chop)
matchID = raw_input("Enter match ID (four digit number in CSGL URL): ")
driver.get("https://csgolounge.com/match?m="+matchID)
问题是,我认为我没有在原始代码中使用“Adblock-plusv1.4.1.crx”替换正确的内容
运行“我的修改版本”会返回以下错误:
IOError: Path to the extension doesn't exist
非常感谢您提供的任何帮助或建议。问题是我没有安装chromedriver()。安装之后,我必须在代码中输入chromedriver可执行文件的路径。不管怎么说,这就是有效的代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chop = webdriver.ChromeOptions()
chop.add_extension('/Users/Username_Here/Library/Application Support/Google/Chrome/Default/Extensions/ghahcnmfjfckcedfajbhekgknjdplfcl/LoungeDestroyer_v0.9.3.7.crx')
driver = webdriver.Chrome(executable_path='/Users/Username_Here/Downloads/chromedriver', chrome_options = chop)
# go to the match page
matchID = raw_input("Enter match ID (four digit number in CSGL URL): ")
driver.get("https://csgolounge.com/match?m="+matchID)
另外,我得到扩展路径错误的原因是,我在文件地址中的“用户”一词前面没有正斜杠