簡體   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