Advertisement
silver2row

scathing the web

Apr 28th, 2020
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import csv
  2. import urllib
  3. import urllib.request
  4. from bs4 import BeautifulSoup
  5. # import requests
  6.  
  7. # theurl  = "https://elinux.org/Beagleboard:BeagleBoneBlack#BeagleBone_Black_Description"
  8. # thepage = urllib.request.urlopen(theurl)
  9. # soup    = BeautifulSoup(thepage, "html.parser")
  10.  
  11. theurl  = "https://elinux.org/Beagleboard:BeagleBoneBlack"
  12. thepage = urllib.request.urlopen(theurl)
  13. soup    = BeautifulSoup(thepage, "html.parser")
  14.  
  15. f = csv.writer(open('SecondWebParseII.csv', 'w'))
  16. f.writerow(['Name', 'Link'])
  17.  
  18. print(soup.title.text)
  19. for link in soup.findAll('a'):
  20.     links = link.get('href')
  21.  
  22. for name in soup.findAll('a'):
  23.     names = name.get('href')
  24.  
  25.     f.writerow([names, links])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement