代码之家  ›  专栏  ›  技术社区  ›  Shashi Shankar Singh

使用python将检索到的信息复制到excel/text文件

  •  0
  • Shashi Shankar Singh  · 技术社区  · 7 年前

    我能够浏览一个网站并检索基本上是HTML网站链接的信息。我需要将这些链接复制到Excel/TXT文件中。我已经编写了下面的代码,它复制链接,但随后将其删除,并复制下一个Weblink,最终只留下迭代中的最后一个链接。任何解决方法。

    driver.get("https://mylink")
    elems = driver.find_elements_by_css_selector("[href*=PublicInfoServlet]")
    
    
    for elem in elems:
        abc=elem.get_attribute("href")
        print(abc) 
    
    with open('Fast.txt', 'w') as myfile: # This line even if put inside the 
                                               for loop still gives the same result.
         myfile.write(abc)
    

    看起来我没有正确地迭代,这导致了这个错误。任何帮助都将非常感谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Shashi Shankar Singh    7 年前