RatemyProfessor网站中的Web爬网“检查”元素部分

时间:2018-08-30 13:26:09

标签: python python-3.x google-chrome web-scraping inspect-element

我是python的新手,想看看是否有任何方法可以废弃RatemyProfessor网站的inspect Element部分。我的目标是获取仅位于该区域的所有教授ID。

当尝试获取我尝试过的代码时。.

import requests

r = requests.get('http://www.ratemyprofessors.com/search.jsp?queryBy=schoolId&schoolName=California+State+University%2C+Northridge&schoolID=163&queryoption=TEACHER')

print (r.text)

但不幸的是,它仅收到源页面信息,而没有提供id信息。 The id's are located in the Inspect Element section, and I was wondering if there is a special link I'm just not seeing that would help me extract this data

这是针对大学项目的,如果有人好奇,任何建议都会有所帮助!

再次感谢!

更新 感谢您提供的所有反馈,我真的很感激,但是我仍然不了解如何通过源代码链接获取元素信息的逻辑

Here I placed arrows indicating what i'm seeing, the link in my "requests.get" provides the code on the left, and my goal is to find a url, or something to be able to extract the information which is on the right.

我真的很想了解发生了什么事情,以及解决该问题的正确方法,如果有人可以向我解释如何实现这一目标的过程,我将不胜感激。

再次感谢大家的贡献,我真的很感激!

2 个答案:

答案 0 :(得分:1)

请注意:从我的教授TOS那里刮取他们网站上的数据是违反的。您可能要放弃这个项目。

答案 1 :(得分:0)

我没有测试,但是您可以使用lib beautifulSoup库来解析hml代码,然后再使用“ result-list”类查找所有div并使用所有“ li” html代码创建一个find_all。现在,您可以获取该li的ID,拆分结果并获得最后一个位置。像这样:

import requests
from bs4 import BeautifulSoup

r = requests.get('http://www.ratemyprofessors.com/search.jsp?queryBy=schoolId&schoolName=California+State+University%2C+Northridge&schoolID=163&queryoption=TEACHER')
page = BeautifulSoup(r.content, 'html.parser')
for divtag in soup.find_all('div', {'class': 'result-list'}):
    for litag in ultag.find_all('li'):
        print litag.text

我没有测试我的代码,但逻辑是这样。