【发布时间】:2016-07-22 17:57:42
【问题描述】:
我正在尝试从类似这样的页面中抓取匹配信息(页面格式相同,但对于不同的匹配显然具有不同的值):https://csgolounge.com/match?m=8967
问题是,我想要的信息只有在您使用 Chrome 扩展程序“Lounge Destroyer”时才会显示......经过大量的试验和错误,我终于想通了,为了获得这些信息,我使用的python脚本必须以某种方式将该扩展名“包含在其中”。我在这里浏览了其他答案,并从另一个 stackoverflow 线程中找到了这段代码,该线程演示了如何在使用 selenium 时添加扩展:
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)
我去Chrome Extension Downloader为LoungeDestroyer获取.crx文件,将它放在chrome扩展文件夹中(从“获取信息”中获取文件地址),并为我的目的稍微修改了上面的代码以获得以下:
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-Plus_v1.4.1.crx”是正确的。
运行我修改后的版本会返回以下错误:
IOError: Path to the extension doesn't exist
非常感谢任何帮助或建议。
【问题讨论】:
标签: python google-chrome selenium google-chrome-extension web-scraping