我有下面的代码从网页中提取一段 HTML 元素。我需要使用检索到的元素创建一个新的 html 文档。任何相同的建议。
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32\chromedriver.exe', chrome_options=options)
driver.implicitly_wait(10)
driver.get("https://mylink") #original link from where I am retrieving other web links
elems = driver.find_elements_by_css_selector("[href*=PublicInfoServlet]")#Looking for other weblinks and storing in this variable
for elem in elems:
abc=elem.get_attribute("href") #iterating over all the weblinks retrieved.
print(abc)
page = urllib.request.urlopen(abc)
soup = BeautifulSoup(page,'html.parser')
a=soup.find("div", {"id": "SPrint"}) #extracting the elements under the DIV id Sprint.
print(a)
如何使用变量 (a) 下捕获的值创建新的 html 文档?