获取网页源代码:
引入组件:【from selenium import webdriver】、
【from selenium.webdriver.chrome.options import Options】
构建浏览器链接:
chrome_options = Options()chrome_options.add_argument('--headless')driver = webdriver.Chrome(options=chrome_options)
获取网页所有源代码:
driver.get_attribute('/telegraph')
获取指定位置网页源代码:
driver.get('/telegraph') # 打开网页# 获取指定标签下的网页源代码clsxpath = driver.find_element_by_xpath('//div[@class="b-c-e6e7ea telegraph-list"][' + str(count-i) + ']')# 转换为文本格式leachText =clsxpath.get_attribute('innerHTML')