【问题标题】:Web Scraping "Inspect" Element section in RatemyProfessor WebsiteRatemyProfessor 网站中的网页抓取“检查”元素部分
【发布时间】:2019-02-05 11:18:54
【问题描述】:

我对 python 比较陌生,想看看是否有任何方法可以取消 RatemyProfessor 网站的检查元素部分。我的目标是获取仅位于该区域的所有教授 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 进行网络扫描的信息。
  • 使用BeautifulSoup 进行网页抓取。在这里,您只是发送请求并显示页面源。 [链接] (crummy.com/software/BeautifulSoup/bs4/doc)

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


【解决方案1】:

我没有测试,但是您可以使用 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

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

【讨论】:

    【解决方案2】:

    请注意:Rate My Professors TOS 从他们的网站上抓取数据是违法的。你可能想放弃这个项目。

    【讨论】:

      猜你喜欢
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-03
      • 2018-12-27
      相关资源
      最近更新 更多