简体   繁体   English

使用python从交互式网页中提取数据

[英]Extracting data from interactive webpage using python

I am relatively a freshman for python. 我是python的新生。 I just learnt how to identify urls in a webpage using python. 我刚刚学习了如何使用python识别网页中的网址。 However, now I want to extract the data from the chart in the webpage. 但是,现在我想从网页中的图表中提取数据。
http://index.baidu.com/?tpl=trend&word=%D0%CB%D2%B5%D6%A4%C8%AF http://index.baidu.com/?tpl=trend&word=%D0%CB%D2%B5%D6%A4%C8%AF

I have three questions for which I need opinions. 我有三个问题需要我提出意见。

  1. It requires login-in to see the webpage. 需要登录才能查看该网页。 (username:18521057966; pw:saifmf) (用户名:1​​8521057966; pw:saifmf)
  2. Cannot find the data from the source code (html I am assuming) 无法从源代码中找到数据(我假设是html)
  3. If we can find which part is the chart, how can we extract the data. 如果我们可以找到图表的哪一部分,那么如何提取数据。
  1. Use Selenium with Python bindings . Selenium与Python绑定结合使用 I recommend this because the page uses JavaScript to complete the login. 我建议这样做是因为页面使用JavaScript来完成登录。
  2. If the information appears on the page, then it is available to you too. 如果该信息显示在页面上,那么您也可以使用该信息。 In other words, if the browser can see the information (which it can if it's rendering it), then you can see it too. 换句话说,如果浏览器可以看到该信息(在呈现信息时可以看到),那么您也可以看到它。 It is likely in the source code. 它可能在源代码中。 Use Google chrome, hover over the element you wish to examine, right click on it, and then select "Inspect element." 使用Google chrome,将鼠标悬停在您要检查的元素上,右键单击它,然后选择“检查元素”。 This will bring up the inspector. 这将调出检查员。 Even if something isn't available in the source code, the inspector ( ctrl+shift+i ) can see it. 即使源代码中没有可用的内容,检查器( ctrl+shift+i )也可以看到它。
  3. That depends. 那要看。 I would first recommend getting that far. 我首先建议您走得更远。 Once you've found the info in the inspector, you can select the element and get the text using selenium and then output it in whatever form you wish (build a CSV for instance). 在检查器中找到信息后,您可以选择元素并使用硒获取text ,然后以所需的任何形式输出(例如,构建CSV )。 This question discusses getting text from an element further. 该问题讨论了进一步从元素获取文本的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM