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:
This prints the output with "name on top and URL on bottom", such as:
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
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import requests # BeautifulSoup is imported with the name bas4 import bs4 # 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 : print (link.get( 'href' )) else : print ( '----------------------------' ) # Just a line break |
1 2 3 4 5 6 7 8 9 10 11 |
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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
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