import requests from bs4 import BeautifulSoup # Base URL for the database of MIT CS professors base_url = "https://www.eecs.mit.edu/" # Make a request to the database of MIT CS professors response = requests.get(base_url, verify=True) # Check if the request was successful if response.status_code == 200: # Parse the HTML content of the page soup = BeautifulSoup(response.text, "html.parser") # Find the elements containing the professor information professor_elements = soup.find_all("div", class_="views-row") # Loop through the professor elements and extract their information for i, professor in enumerate(professor_elements): if i == 30: break name = professor.find("h2").text email = professor.find("a", class_="email").text area_of_interest = professor.find("div", class_="field-name-field-research-areas").text # Store the information for each professor in a dictionary professor_dict = { "name": name, "email": email, "area_of_interest": area_of_interest } # Append the dictionary to a list professor_info.append(professor_dict) # If the request was not successful, print an error message else: print("Failed to retrieve data from the website.") # Print the list of dictionaries print(professor_info)
为什么代码无法从网站检索数据?这是一个剪贴器,它可以访问麻省理工学院的教授数据库,收集他们的电子邮件、姓名和电子邮件机器人感兴趣的区域,但剪贴器无法在atm机上工作。