Python Forum
NameError: name 'bsObj' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: name 'bsObj' is not defined
#5
Here is the code:

from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
pages = set()
def getLinks(pageUrl):
 global pages
 html = urlopen("http://en.wikipedia.org"+pageUrl)
 try:
    print(bsObj.h1.get_text())
    print(bsObj.find(id ="mw-content-text").findAll("p")[0])
    print(bsObj.find(id="ca-edit").find("span").find("a").attrs['href'])
 except AttributeError:
   
    print("This page is missing something! No worries though!")
for link in bsObj.findAll("a", href=re.compile("^(/wiki/)")):
   if 'href' in link.attrs:
       if link.attrs['href'] not in pages:
#We have encountered a new page
         newPage = link.attrs['href']
         print("----------------\n"+newPage)
         pages.add(newPage)
         getLinks(newPage)
getLinks("")
That it, I found this on the web and change some of it, the findAll is defined I think = print(bsObj.find(id ="mw-content-text").findAll("p")[0])

Thank you Dodgy
Reply


Messages In This Thread
RE: NameError: name 'bsObj' is not defined - by Blue Dog - Oct-22-2016, 07:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError :name 'name' is not defined Suzzy_ 4 19,111 Dec-27-2019, 09:04 AM
Last Post: LeanbridgeTech
  NameError: Name 'path' is not defined aniyanetworks 9 59,963 Jun-29-2018, 03:21 PM
Last Post: gontajones
  NameError: name 'download' is not defined ntdropper 3 11,435 Jan-13-2018, 07:18 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020