I am a Newbie with the below question
I have successfully scrapped a website that looks for all weblinks on that site and stores them in a list, i print the list and can see approx 45 weblinks.
I want to send the data to a .csv file. My issue is the results is its taking the last web link from the list and printing it in one row with each character populating a single cell.
My goal is to print all the 45 links in one column with each one under the other…
The code is below… thank you for any help
‘’’
def init(self):
print(“Running WebScraper”)
r = requests.get(‘Python Tutorial | Python Programming Language Tutorial for Beginners’)
soup = BeautifulSoup(r.content, 'html.parser')
for a_href in soup.find_all("a", href=True):
results = (a_href["href"])
csv_file = 'C:/Users/twbry/OneDrive/Desktop/Python_Project/academic.csv'
with open(csv_file, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
#for item in results:
writer.writerows([results])
print("print results", results)
‘’’