网页搜索“检查”RatemyProfessor网站中的元素部分

问题描述 投票:0回答:2

我是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.

我真的想了解发生了什么,以及正确的解决方法,如果有人能够向我解释如何实现这一目标,我将非常感激。

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

python python-3.x google-chrome web-scraping inspect-element
2个回答
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

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


1
投票

只是一个抬头:它反对我的教授TOS从他们的网站刮取数据。您可能想放弃这个项目。

© www.soinside.com 2019 - 2024. All rights reserved.