首页 > 解决方案 > 为什么通过 url 循环获取页面源只能获取 url 页面源的一半?Python

问题描述

我正在尝试为某些公司名称抓取一些公共 LinkedIn 数据。linkedin_list_of_urls 是我从 google 上抓取的 LinkedIn URL 列表(其中有 96 个)。当我尝试将页面源放入列表 source_code_lists 时,它只返回 46 个页面源。这是正常的吗?此外,我对编码非常陌生,因此非常感谢任何改进代码的提示。

source_code_lists = []
for linkedin_list_of_url in linkedin_list_of_urls: 
    driver.get(linkedin_list_of_url)
    sleep(2.5)
    about_in_button = driver.find_element_by_link_text("About")
    about_in_button.click()
    sleep(1.0)
    sel = Selector(text=driver.page_source)
    sleep(1.0)
    source_code_lists.append(sel)
driver.quit()

len(linkedin_list_of_urls) 
len(source_code_lists)

len(linkedin_list_of_urls) = 92
len(source_code_lists) = 46

我怎么得到len(source_code_lists) = 92

标签: pythonseleniumselenium-webdriver

解决方案


推荐阅读