python - Correct Library Usage: requests w/ bs4.BeautifulSoup? -


I just use urllib2 to switch to request In the Library Urlib, you use the BeautifulSoup to drag the html elements using the findAll (tag = 'element') function, do I use the SunderSub in the same way I request or request that a function simplifies this process?


urllib2


  Import bs4 import from urlib2 import as auspicious BS response = urllib2.urlopen ('http: //stackoverflow.com / ') Soup = BS (reaction) for one in soup. Remove all ('A'): Drag the tag using a [[href]   

print


  Import feedback feedback = request.get ('http://stackoverflow.com/'). All ('A'): A [[href]    

Only one Getting data from the URL makes it easy, especially if there are redirects, etc. It does not parse the body of HTML for you, you should still do this with BeautifulSoup and for this you should import the second piece of code, and something like this:

  soup = BS (response.text)    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -