I am trying to scrape a website and then save the links to a text file. in the text file, I would like to delete any line that does not start with "/". How could I do that? This is everything I have so far:
import requests from bs4 import BeautifulSoup page = requests.get("https://wiki.stardewvalley.net/Stardew_Valley_Wiki") soup = BeautifulSoup(page.content, 'html.parser') wikilinks = [] for con in soup.find_all('div', class_="mainmenuwrapper"): for links in soup.find_all('a', href=True): if links.text: wikilinks.append(links['href']) # print(wikilinks) with open('./scrapeNews/output.txt', 'w') as f: for item in wikilinks: f.write("%s\n" % item) https://stackoverflow.com/questions/66485609/i-am-trying-to-delete-lines-of-text-in-python-that-starts-with March 05, 2021 at 09:50AM
没有评论:
发表评论