Scraping Wikipedia Article (Name in 1 column & URL in 2nd column) ->CSV! Anyone?
Targeted Columns & All Links
Does anyone know how to accomplish this feat?
I followed this tutorial/blog:
https://www.kindacode.com/article/extrac...ul-soup-4/
This code:
Thank you everyone for this forum! I will append this thread if I start to find answers, rather than replies as I was doing earlier in error! Appreciate the correction and forum/assistance!
Best Regards,
Brandon Kastning
Targeted Columns & All Links
Does anyone know how to accomplish this feat?
I followed this tutorial/blog:
https://www.kindacode.com/article/extrac...ul-soup-4/
This code:
import requests # BeautifulSoup is imported with the name bas4 import bs4 URL = 'https://en.wikipedia.org/wiki/List_of_counties_in_Washington' # Fetch all the HTML source from the url response = requests.get(URL) soup = bs4.BeautifulSoup(response.text, 'html.parser') links = soup.select('a') # Print out the result for link in links: print(link.get_text()) if link.get('href') != None: if 'https://' in link.get('href'): print(link.get('href')) else: print('https://en.wikipedia.org' + link.get('href')) # Convert relative URL to absolute URL print('----------------------------') # Just a line breakThis prints the output with "name on top and URL on bottom", such as:
Counties ---------------------------- Adams https://en.wikipedia.org/wiki/Adams_County,_Washington ---------------------------- Asotin https://en.wikipedia.org/wiki/Asotin_County,_Washington ---------------------------- Benton https://en.wikipedia.org/wiki/Benton_County,_Washington ----------------------------I would like to store the name in 1 column and the URL in a 2nd column and send it to a CSV
Thank you everyone for this forum! I will append this thread if I start to find answers, rather than replies as I was doing earlier in error! Appreciate the correction and forum/assistance!
Best Regards,
Brandon Kastning
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo