【发布时间】:2021-02-05 17:07:08
【问题描述】:
我正在使用 chromedriver、selenium 和 BeatifulSoup 抓取以下网页:
我使用 selenium 与网页交互,在确定显示整个网页后,我使用 BeatifulSoup 来定位和提取信息
我使用 BeatifulSoup 寻找这个元素
img = n.find("img", {"class":"ng-lazyloading"})["src"]
当我在有头(无头)模式下运行脚本时,我得到了所有 src 属性,但是当我使用无头模式运行脚本时,我只得到了最后一个 src。
如何使用无头模式获取整个 src 属性。
这是设置的参数:
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
options.add_argument("--headless")
options.add_argument('--no-sandbox')
options.add_argument('window-size=1051x806')
#options.add_argument("start-maximized")
# options.use_chromium = True
prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path= ChromeDriverManager().install(), options=options)
driver.set_page_load_timeout(30)
driver.implicitly_wait(10)
look at the output
【问题讨论】:
标签: python selenium beautifulsoup