虽然我知道有人问过这个问题,但我找不到合适的答案,所以我又问了一遍。我使用PhantomJS来抓取网站,但在Mac上速度非常慢,所以我想要Chrome浏览器,但Chrome浏览器显示浏览器很糟糕,我可以将其隐藏吗?我尝试了如下代码,仍然显示一个小浏览器窗口..
cat Input_file
test name etc xyz abc
chumma hero type film
grep "test" Input_file
test name etc xyz abc ---> Output
grep "fill" file445
NO Output as no match found.
答案 0 :(得分:5)
参考:how-could-i-start-a-selenium-browserlike-firefox-minimized
您可以在显示器上移动浏览器窗口,如下所示:
driver.set_window_position(-10000,0)
答案 1 :(得分:1)
谷歌在4月4日宣布你可以无头跑。
https://developers.google.com/web/updates/2017/04/headless-chrome
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver"), chrome_options=chrome_options)
你应该确定的事情很少
答案 2 :(得分:0)
尝试一下!
https://beomi.github.io/2017/09/28/HowToMakeWebCrawler-Headless-Chrome/
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
# OR options.add_argument("--disable-gpu")
driver = webdriver.Chrome('chromedriver', chrome_options=options)
答案 3 :(得分:0)
我认为它会奏效。
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('headless')
chrome_options.add_argument('window-size=1920x1080')
chrome_options.add_argument("disable-gpu")
driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)
driver.get('http://google.com')
print(driver.title)
driver.implicitly_wait(3)
driver.get_screenshot_as_file('googleHomePage.png')
driver.quit()