Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scraping a webpage with BS4
#4
Quote:what does the [-1] refer to in the url.split line
the [-1] is an index to the last item in the slice of the split, so it gets the file name.
you have to be careful with this though, and look for additional attributes after the file name, like '?ei=wvJQXPryB6m2ggfQx76wAg&q', etc. which I didn't do here as it didn't appear that it would be an issue.
Quote:I don't totally follow the code. I received an error on the first line when trying to run the code. What does the 'n' refer to?
please note that I stated code was untested. If that line was used, it would should read:
    for n, link in enumerate(soup.find_all('a')):
but since n is not needed, it should be removed, and the line should be:
    for link in soup.find_all('a'):
what enumerate does is return the current iteration of the loop
Reply


Messages In This Thread
Scraping a webpage with BS4 - by SBF12345 - Jan-28-2019, 10:10 PM
RE: Scraping a webpage with BS4 - by Larz60+ - Jan-29-2019, 04:19 AM
RE: Scraping a webpage with BS4 - by SBF12345 - Jan-29-2019, 07:18 PM
RE: Scraping a webpage with BS4 - by Larz60+ - Jan-30-2019, 12:47 AM

Forum Jump:

User Panel Messages

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