Я пытаюсь перемещаться по сайту с помощью Beautifulsoup.Я открываю первую страницу и нахожу ссылки, по которым хочу перейти, но когда я прошу красивый суп открыть следующую страницу, ни один из HTML не анализируется, и он просто возвращает это
<function scraper at 0x000001E3684D0E18>
Я попытался открытьвторая страница в своем собственном скрипте, и она прекрасно работает, поэтому проблема связана с анализом страницы с другой страницы.
У меня ~ 2000 ссылок, по которым мне нужно перейти, поэтому я создал функцию, которая проходит черезих.Вот мой сценарий до сих пор
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import lxml
# The first webpage I'm parsing
my_url = 'https://mars.nasa.gov/msl/multimedia/raw/'
#calls the urlopen function from the request module of the urllib module
# AKA opens up the connection and grabs the page
uClient = uReq(my_url)
#imports the entire webpage from html format into python.
# If webpage has lots of data this can take a long time and take up a lot of
space or crash
page_html = uClient.read()
#closes the client
uClient.close()
#parses the HTML using bs4
page_soup = soup(page_html, "lxml")
#finds the categories for the types of images on the site, category 1 is
RHAZ
containers = page_soup.findAll("div", {"class": "image_list"})
RHAZ = containers[1]
# prints the links in RHAZ
links = []
for link in RHAZ.find_all('a'):
#removes unwanted characters from the link making it usable.
formatted_link = my_url+str(link).replace('\n','').split('>')
[0].replace('%5F\"','_').replace('amp;','').replace('<a href=\"./','')
links.append(formatted_link)
print (links[1])
# I know i should be defining a function here.. so ill give it a go.
def scraper():
pic_page = uReq('links[1]') #calls the first link in the list
page_open = uClient.read() #reads the page in a python accessible format
uClient.close() #closes the page after it's been stored to memory
soup_open = soup(page_open, "lxml")
print (soup_open)
print (scraper)
Нужно ли очищать ранее загруженный HTML-файл в beautifulsoup, чтобы я мог открыть следующую страницу?Если так, как бы я это сделал?Спасибо за любую помощь