繁体   English   中英

Python网络抓取表

[英]Python Web-Scraping Table

我正在尝试使用pythin从网站上抓取一些数据。 该网站包含许多不同的锻炼,每个锻炼都有自己的数据。 我已经弄清楚了如何从每个特定的锻炼中抓取数据,但是要做到这一点,我必须在url中提供一个特定的锻炼ID。 主页似乎显示在表格中列出所有这些锻炼ID,但是当我使用漂亮的汤搜索html文档时,将返回以下表格数据:

<table class="table table-striped table-hover">
<thead>
<tr>
<th ng-click="order('class_name')" style="cursor:pointer;">Name</th>
<th ng-click="order('location')" style="cursor:pointer;">Location</th>
<th ng-click="order('trainer')" style="cursor:pointer;">Instructor</th>
<th ng-click="order('class_date_sec')" style="cursor:pointer;">Date</th>
<th ng-click="order('points')" style="cursor:pointer;">OT Points</th>
<th ng-click="order('CALORIES')" style="cursor:pointer;">Total Calories 
(kCal)</th>
</tr>
</thead>
<tbody id="otf-class-body">
<tr calories="{{class.CALORIES | number:0}}" class_date="{{class.class_date}} 
    at {{class.class_time}}" class_name="{{class.class_name}}" date_order=" 
    {{class.date_order}}" id="{{class.CLASSID}}" loc="{{class.loc}}" 
    location=" {{class.location}}" ng-click="view(class.CLASSID, 
    class.at_home)" ng-repeat="class in classes | orderBy:predicate:reverse" 
    points=" {{class.points | number:0}}" trainer="{{class.trainer}}">
<td>{{class.class_name}}</td>
<td>{{class.location}}</td>
<td>{{class.trainer}}</td>
<td>{{class.class_date}} at {{class.class_time}}</td>
<td>{{class.points | number:0}}</td>
<td>{{class.CALORIES | number:0}}</td>
</tr>
</tbody>
</table>

如您所见,没有实际的文本,而是所有信息似乎都是某种变量(我的html知识非常有限)。 看来我想要的信息将是所有列表:

class.CLASSID

是否可以使用python获取此信息? 或者它使用一些我无法访问的api。

任何帮助表示赞赏。

好的队友:)我认为这可以正常工作,但是使用python3.x希望它会有所帮助

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

options =webdriver.ChromeOptions()
options.add_argument('headless')
# If you want it headless uncomment the line underneath and comment  out driver = webdriver.Chrome()
# driver = webdriver.Chrome(chrome_options = options)
driver = webdriver.Chrome()
url = ('https://carmel.orangetheoryfitness.com/login')
driver.get(url)
inputElement = driver.find_element_by_id("email")
inputElement.send_keys("YOUR EMAIL HERE")#put your email between the ""s
inputElement = driver.find_element_by_id("password")
inputElement.send_keys("YOUR PASSWORD HERE")#put your password between the ""s
inputElement.send_keys(Keys.ENTER)
driver.get("carmel.orangetheoryfitness.com/apps/otf/classes")
html = driver.page_source
print(html)

概括

因为它希望您登录,所以我知道解决方案是使用硒。 当然,还有其他方法,希望与大家分享:)我建议您无头使用它,因为它的混乱程度较小,浏览器将在后台运行,但要进行调试,请在准备好后使用它。只需注释掉没有头的代码,一切都会像魅力一样起作用,希望我能帮助您交配! 随时为任何问题加油

编码!

暂无
暂无

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

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