from bs4 import BeautifulSoup soup = BeautifulSoup(html_doc)
print(soup.prettify()) # <html> # <head> # <title> # The Dormouse's story # </title> # </head> # <body> # <p class="title"> # <b> # The Dormouse's story # </b> # </p> # <p class="story"> # Once upon a time there were three little sisters; and their names were # <a class="sister" href="http://example.com/elsie" id="link1"> # Elsie # </a> # , # <a class="sister" href="http://example.com/lacie" id="link2"> # Lacie # </a> # and # <a class="sister" href="http://example.com/tillie" id="link2"> # Tillie # </a> # ; and they lived at the bottom of a well. # </p> # <p class="story"> # ... # </p> # </body> # </html>
# 获取所有地景链接,存入列表 def getTargetLinks(html): soup = BeautifulSoup(html) list=[] #print(soup.prettify()) for child in soup.find_all('area'): list.append(child['href']) print("Get Target Links Success!") return list
# 将地景链接逐行写入文件 def writeToFile(linkList): file = open('./sceneLink.txt','w') for link in linkList: file.write(link) file.write('\t\n') print("Write Target Link To File Success!") file.close()
if __name__ == "__main__": link = "http://www.flightgear.org/legacy-Downloads/scenery-v2.12.html" html=getUriContent(link) linkList=getTargetLinks(html) writeToFile(linkList)
下载世界地景
1 2 3 4
for line in $(cat sceneLink.txt) do axel -n 10 $line done