Selecting Checkboxes in a table with selenium - python

So I'm trying to select the 4 swimming checkboxes on this page and then click next, using selenium with python:
https://i.stack.imgur.com/Lo2ok.png
It has this html code:
<main class="scheduleVisitOnline container" role="main">
<!-- See app.jsx for React component -->
<div id="schedule-visit-wizard-app">
<div class="chooseMembersStep">
<h1 class="page-title">
Schedule a Visit
</h1>
<p>
<strong>
Ann Arbor YMCA
</strong>
<br/>
<a href="#">
Change Branch
</a>
</p>
<div class="chooseMembersStep__members">
<label class="control-label">
Select visiting members and any reservation-only areas you intend to utilize
</label>
<table class="chooseMembersStep__members-table">
<tbody>
<tr class="chooseMembersStep__member">
<td>
<div class="pretty p-svg p-curve">
<input checked="" id="member_3572218" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td colspan="2">
<label class="chooseMembersStep__member-name" for="member_3572218">
Patrick McKeever
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_39b9bf20-6493-4bd8-b2c4-6f6a4ab5a69d" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_39b9bf20-6493-4bd8-b2c4-6f6a4ab5a69d">
Hoops M-F / 7-8a /- 2 Half Courts (1 reservation per member family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_9a486991-672e-4a87-9130-05f379344968" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_9a486991-672e-4a87-9130-05f379344968">
Hoops M-S / 8a-8p /- 4 Half Courts (1 reservation per member family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_23d2d590-475d-44cd-84fd-c071bf299f89" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_23d2d590-475d-44cd-84fd-c071bf299f89">
Indoor Wellness Center
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_b6470dcf-ab5d-44e5-85e2-4a50a1f7ffc7" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_b6470dcf-ab5d-44e5-85e2-4a50a1f7ffc7">
Lap Pool - Lane 1 (1 reservation allows 4 members from same family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_34b69cbf-c890-4090-912e-1a2e32c805a9" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_34b69cbf-c890-4090-912e-1a2e32c805a9">
Lap Pool - Lane 2 (1 reservation allows 4 members from same family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_7f453950-a5ba-424a-ac1e-a8c968519ab7" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_7f453950-a5ba-424a-ac1e-a8c968519ab7">
Lap Pool - Lane 3 (1 reservation allows 4 members from same family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_28fed658-ad4e-4721-8b90-d6c943f0fac9" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_28fed658-ad4e-4721-8b90-d6c943f0fac9">
Lap Pool - Lane 4 (1 reservation allows 4 members from same family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_c22ab33c-7850-4a52-a6e9-8737647ea54f" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_c22ab33c-7850-4a52-a6e9-8737647ea54f">
Lap Pool - Lane 5 (1 reservation allows 4 members from same family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_24177575-8769-405b-af6a-5e5afdb10c56" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_24177575-8769-405b-af6a-5e5afdb10c56">
Lap Pool - Lane 6 (1 reservation allows 4 members from same family account)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_0ee4cec1-2149-4af5-9c76-22abc6574d64" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_0ee4cec1-2149-4af5-9c76-22abc6574d64">
Showers (Reservation only necessary if you don't have a reservation in another area of the building)
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-area">
<td>
</td>
<td class="chooseMembersStep__member-area-checkbox-col">
<div class="pretty p-svg p-curve">
<input id="3572218_084dfd23-3ab5-4624-bcc8-bb7f8a25d30d" type="checkbox"/>
<div class="state p-success">
<svg class="svg svg-icon" viewbox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white; fill: white;">
</path>
</svg>
<label>
</label>
</div>
</div>
</td>
<td class="chooseMembersStep__member-area-name-col">
<label class="chooseMembersStep__area-name" for="3572218_084dfd23-3ab5-4624-bcc8-bb7f8a25d30d">
Track
</label>
</td>
</tr>
<tr class="chooseMembersStep__member-spacer">
<td colspan="3">
</td>
</tr>
</tbody>
</table>
</div>
<div class="ctas">
<button class="btn" type="button">
Back
</button>
<button class="btn btn-primary" type="button">
Next
</button>
</div>
</div>
</div>
<div style="clear: both;">
</div>
</main>
When I run the following lines of python though, the driver doesn't switch to the next page, indicating none of the checkboxes have been clicked (it won't allow you to switch pages if you don't click on at least 1 box.
wd.find_element_by_id("3572218_b6470dcf-ab5d-44e5-85e2-4a50a1f7ffc7").click()
wd.find_element_by_id("3572218_34b69cbf-c890-4090-912e-1a2e32c805a9").click()
wd.find_element_by_id("3572218_7f453950-a5ba-424a-ac1e-a8c968519ab7").click()
wd.find_element_by_id("3572218_28fed658-ad4e-4721-8b90-d6c943f0fac9").click()
wd.find_element_by_id("3572218_c22ab33c-7850-4a52-a6e9-8737647ea54f").click()
wd.find_element_by_id("3572218_24177575-8769-405b-af6a-5e5afdb10c56").click()
#actions = ActionChains(wd)
#actions.move_to_element(element).click(element).perform()
#wd.find_element_by_xpath('//*[#id="schedule-visit-wizard-app"]/div/div[1]/table/tbody/tr[5]')
#time.sleep(1)
wd.find_element_by_xpath('//*[#id="schedule-visit-wizard-app"]/div/div[2]/button[2]').click()
The commented stuff was just me trying to see if actionchains could fix my problem.
Any ideas?

driver.find_elements_by_xpath("//td[.//label[contains(.,'Lap Pool - Lane')]]") will give you all 6 pool records. Now if you want to clicks on first 4 pool elements you need manipulate the list.
Now iterate over and click.
for chk in driver.find_elements_by_xpath("//td[.//label[contains(.,'Lap Pool - Lane')]]")[:4]:
chk.click()
You can use below code block as well
for chk in driver.find_elements_by_xpath("//td[.//label[contains(.,'Lap Pool - Lane')]]")[:4]:
chk.find_element_by_xpath("./preceding-sibling::td[1]//input").click()

maybe find_element_by_xpath helps you.
Try that:
wd.find_element_by_xpath(".//*[contains(text(), 'text on the list item you want to click')]").click()
You can replace the text with text like:
Lap Pool - Lane 1 (1 reservation allows 4 members from same family account)

Related

Get available dates using selenium and python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm new to Python and web scraping. I have the following calendar as a table and i would like to extract available dates which are in Green background color.
Below is the HTML source:
<div id="calendar" class="fc fc-ltr">
<table class="fc-header" style="width:100%">
<tbody>
<tr>
<td class="fc-header-left"><span class="fc-button fc-button-prev fc-state-default fc-corner-left fc-corner-right" unselectable="on" style="display: inline-block;"><span class="fc-text-arrow">‹</span></span>
</td>
<td class="fc-header-center"><span class="fc-header-title"><h2>March 2020</h2></span></td>
<td class="fc-header-right"><span class="fc-button fc-button-next fc-state-default fc-corner-left fc-corner-right" unselectable="on" style="display: inline-block;"><span class="fc-text-arrow">›</span></span>
</td>
</tr>
</tbody>
</table>
<div class="fc-content" style="position: relative;">
<div class="fc-view fc-view-month fc-grid" style="position:relative" unselectable="on">
<div class="fc-event-container" style="position:absolute;z-index:8;top:0;left:0"></div>
<table class="fc-border-separate" style="width:100%" cellspacing="0">
<thead>
<tr class="fc-first fc-last">
<th class="fc-day-header fc-sun fc-widget-header fc-first" style="width: 50px;">Sun</th>
<th class="fc-day-header fc-mon fc-widget-header" style="width: 50px;">Mon</th>
<th class="fc-day-header fc-tue fc-widget-header" style="width: 50px;">Tue</th>
<th class="fc-day-header fc-wed fc-widget-header" style="width: 50px;">Wed</th>
<th class="fc-day-header fc-thu fc-widget-header" style="width: 50px;">Thu</th>
<th class="fc-day-header fc-fri fc-widget-header" style="width: 50px;">Fri</th>
<th class="fc-day-header fc-sat fc-widget-header fc-last">Sat</th>
</tr>
</thead>
<tbody>
<tr class="fc-week fc-first">
<td class="fc-day fc-sun fc-widget-content fc-future fc-first" data-date="2020-03-01">
<div style="min-height: 40px;">
<div class="fc-day-number">1</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-mon fc-widget-content fc-future" data-date="2020-03-02">
<div>
<div class="fc-day-number">2</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-tue fc-widget-content fc-future" data-date="2020-03-03">
<div>
<div class="fc-day-number">3</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-wed fc-widget-content fc-future" data-date="2020-03-04">
<div>
<div class="fc-day-number">4</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-thu fc-widget-content fc-future" data-date="2020-03-05">
<div>
<div class="fc-day-number">5</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-fri fc-widget-content fc-future" data-date="2020-03-06" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">6</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-sat fc-widget-content fc-future fc-last" data-date="2020-03-07" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">7</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
</tr>
<tr class="fc-week">
<td class="fc-day fc-sun fc-widget-content fc-future fc-first" data-date="2020-03-08">
<div style="min-height: 39px;">
<div class="fc-day-number">8</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-mon fc-widget-content fc-future" data-date="2020-03-09" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">9</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-tue fc-widget-content fc-future" data-date="2020-03-10">
<div>
<div class="fc-day-number">10</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-wed fc-widget-content fc-future" data-date="2020-03-11">
<div>
<div class="fc-day-number">11</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-thu fc-widget-content fc-future" data-date="2020-03-12">
<div>
<div class="fc-day-number">12</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-fri fc-widget-content fc-future" data-date="2020-03-13" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">13</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-sat fc-widget-content fc-future fc-last" data-date="2020-03-14" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">14</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
</tr>
<tr class="fc-week">
<td class="fc-day fc-sun fc-widget-content fc-future fc-first" data-date="2020-03-15">
<div style="min-height: 39px;">
<div class="fc-day-number">15</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-mon fc-widget-content fc-future" data-date="2020-03-16">
<div>
<div class="fc-day-number">16</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-tue fc-widget-content fc-future" data-date="2020-03-17">
<div>
<div class="fc-day-number">17</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-wed fc-widget-content fc-future" data-date="2020-03-18">
<div>
<div class="fc-day-number">18</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-thu fc-widget-content fc-future" data-date="2020-03-19" style="background-color: rgb(255, 150, 202); cursor: pointer;">
<div>
<div class="fc-day-number">19</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-fri fc-widget-content fc-future" data-date="2020-03-20" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">20</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-sat fc-widget-content fc-future fc-last" data-date="2020-03-21" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">21</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
</tr>
<tr class="fc-week">
<td class="fc-day fc-sun fc-widget-content fc-future fc-first" data-date="2020-03-22" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div style="min-height: 39px;">
<div class="fc-day-number">22</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-mon fc-widget-content fc-future" data-date="2020-03-23" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">23</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-tue fc-widget-content fc-future" data-date="2020-03-24" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">24</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-wed fc-widget-content fc-future" data-date="2020-03-25" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">25</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-thu fc-widget-content fc-future" data-date="2020-03-26" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">26</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-fri fc-widget-content fc-future" data-date="2020-03-27" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">27</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-sat fc-widget-content fc-future fc-last" data-date="2020-03-28" style="color: rgb(255, 106, 106);">
<div>
<div class="fc-day-number">28</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
</tr>
<tr class="fc-week">
<td class="fc-day fc-sun fc-widget-content fc-future fc-first" data-date="2020-03-29" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div style="min-height: 39px;">
<div class="fc-day-number">29</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-mon fc-widget-content fc-future" data-date="2020-03-30" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">30</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-tue fc-widget-content fc-future" data-date="2020-03-31" style="background-color: rgb(188, 237, 145); cursor: pointer;">
<div>
<div class="fc-day-number">31</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-wed fc-widget-content fc-other-month fc-future" data-date="2020-04-01" style="background-color: white;">
<div>
<div class="fc-day-number">1</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-thu fc-widget-content fc-other-month fc-future" data-date="2020-04-02" style="background-color: white;">
<div>
<div class="fc-day-number">2</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-fri fc-widget-content fc-other-month fc-future" data-date="2020-04-03" style="background-color: white;">
<div>
<div class="fc-day-number">3</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-sat fc-widget-content fc-other-month fc-future fc-last" data-date="2020-04-04" style="background-color: white;">
<div>
<div class="fc-day-number">4</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
</tr>
<tr class="fc-week fc-last">
<td class="fc-day fc-sun fc-widget-content fc-other-month fc-future fc-first" data-date="2020-04-05" style="background-color: white;">
<div style="min-height: 41.3333px;">
<div class="fc-day-number">5</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-mon fc-widget-content fc-other-month fc-future" data-date="2020-04-06" style="background-color: white;">
<div>
<div class="fc-day-number">6</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-tue fc-widget-content fc-other-month fc-future" data-date="2020-04-07" style="background-color: white;">
<div>
<div class="fc-day-number">7</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-wed fc-widget-content fc-other-month fc-future" data-date="2020-04-08" style="background-color: white;">
<div>
<div class="fc-day-number">8</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-thu fc-widget-content fc-other-month fc-future" data-date="2020-04-09" style="background-color: white;">
<div>
<div class="fc-day-number">9</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-fri fc-widget-content fc-other-month fc-future" data-date="2020-04-10" style="background-color: white;">
<div>
<div class="fc-day-number">10</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
<td class="fc-day fc-sat fc-widget-content fc-other-month fc-future fc-last" data-date="2020-04-11" style="background-color: white;">
<div>
<div class="fc-day-number">11</div>
<div class="fc-day-content">
<div style="position: relative; height: 0px;"> </div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div class="fc-cell-overlay" style="position: absolute; z-index: 3; top: 100.667px; left: 200px; width: 50px; height: 40px;"></div>
</div>
</div>
</div>
Assuming that you already hold the HTML source under selenium driver.page_source so we are going to pass it to the soup and parse it.
from bs4 import BeautifulSoup
soup = BeautifulSoup(driver.page_source, 'html.parser')
for item in soup.findAll("td", {'style': 'background-color: rgb(188, 237, 145); cursor: pointer;'}):
print(item.get("data-date"))
Output:
2020-03-09
2020-03-22
2020-03-23
2020-03-24
2020-03-25
2020-03-26
2020-03-29
2020-03-30
2020-03-31
In case if you don't have bs4 installed, you can install it via pip install bs4 --user

Multiplying functions depending on a previous input

I'm trying to do a little script that writes an html file, this file must have a table which contains two rows that have some information about different products, I managed to get this done, but now I need that this table repeats as many times depending on a previous input data, so for this I thought I could multiply the function which contains the html code but it doesn't work, actually I'm not quite sure what I'm doing here so a little bit of help wouldn't be bad...
This is what I want:
Input ---> How many tables: 3
So the html output file should look something like this
<-- TABLE 1 -->
<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>
<-- TABLE 2 -->
<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>
<-- TABLE 3 -->
<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/>
<span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>
Here is my Python code
import locale
import requests
import urlparse
import json
def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod):
f = open('mkt-output.html','w')
f.write(bloque_prod)
f.close()
if __name__ == '__main__':
sku_01 = raw_input('Ingrese SKU: ')
desc_01 = raw_input('Descripcion de SKU: ')
sku_precio_1 = raw_input('Precio de SKU: ')
sku_02 = raw_input('Ingrese SKU: ')
desc_02 = raw_input('Descripcion de SKU: ')
sku_precio_2 = raw_input('Precio de SKU: ')
bloque_prod = """<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>""".format(sku_01,
sku_01,
desc_01,
sku_02,
sku_02,
desc_02,
' '.join(desc_01.split()[0:3]),
' '.join(desc_01.split()[3:-1]),
desc_01.split()[-1],
sku_01[0:-1],
sku_01[-1],
sku_precio_1,
' '.join(desc_02.split()[0:3]),
' '.join(desc_02.split()[3:-1]),
desc_02.split()[-1],
sku_02[0:-1],
sku_02[-1],
sku_precio_2,
sku_01,
sku_02)
html(sku_01, desc_01, sku_precio_1, sku_02, desc_02, sku_precio_2, bloque_prod)
If you need duplicate data written to the HTML file, you could simply have the html() function write variable bloque_prod multiple times by multiplying it:
def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod,tables):
f = open('mkt-output.html','w')
f.write(bloque_prod * tables)
f.close()
Note the addition of the variable tables for the number of table duplicates.
Then, define variable tables in __main()__:
tables = input('Tables: ')
…and add tables into the last line where you call html()
html(sku_01, desc_01, sku_precio_1, sku_02, desc_02, sku_precio_2, bloque_prod,tables)
Are you looking to write different tables?
Also, if it's necessary to annotate which table is currently being printed, you could add an if statement in:
def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod,tables):
f = open('mkt-output.html','w')
rawHTML = ""
for table in range(0, tables):
rawHTML += ("\n<-- TABLE " + str(table) + " -->\n" + bloque_prod)
f.write(rawHTML)
f.close()
(if you wanted the numbering to start at 1, you'd just change str(table) to str(table + 1))
--EDIT-- It seems that you are looking to create tables with different values. I would rewrite the program as such to do this:
import locale
import requests
import urlparse
import json
def createTable(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2):
bloque_prod = """<table>
<tr>
<td colspan="4" height="30"></td>
</tr>
<tr>
<td width="50" class="width6p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
<td width="30" class="width3p"></td>
<td width="260" class="width44p"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></td>
</tr>
<tr>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span ><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
<td></td>
<td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;">
<span style="font-weight: bold; color:#008EAA" class="font14">{}</span><br />
<span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/>
<span style="font-size:12px;" class="font12">SKU: {}-{}</span><br />
<span style="font-size:18px;" class="font14">$ </span>
<span style="font-size:24px; line-height:30px;" class="font20">{}</span>
<span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br>
</td>
</tr>
<tr>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
<td></td>
<td style="inline-height:0px;padding-top:4px;"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></td>
</tr>
</table>""".format(sku_01,
sku_01,
desc_01,
sku_02,
sku_02,
desc_02,
' '.join(desc_01.split()[0:3]),
' '.join(desc_01.split()[3:-1]),
desc_01.split()[-1],
sku_01[0:-1],
sku_01[-1],
sku_precio_1,
' '.join(desc_02.split()[0:3]),
' '.join(desc_02.split()[3:-1]),
desc_02.split()[-1],
sku_02[0:-1],
sku_02[-1],
sku_precio_2,
sku_01,
sku_02)
return bloque_prod
if __name__ == "__main__":
f = open('mkt-output.html','w+') # Open file in w+ mode so we can append to the end
for table in range(0,input("Tables: ")):
print ("--Table "+str(table)+"--")
sku_01 = raw_input('Ingrese SKU: ')
desc_01 = raw_input('Descripcion de SKU: ')
sku_precio_1 = raw_input('Precio de SKU: ')
sku_02 = raw_input('Ingrese SKU: ')
desc_02 = raw_input('Descripcion de SKU: ')
sku_precio_2 = raw_input('Precio de SKU: ')
f.write(createTable(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2))
f.close()
Hope that helps.

How to find a specific tag by text with BeautifulSoup in Python

<table class="person show-interviews interviews-loaded" application="43352812" current-interview-stage-id="373822" candidate_hiring_plan="52607">
<tbody><tr class="basic-info clickable candidate">
<td class="photo-column" href="/people/34284587?application_id=43352812&src=search">
<img class="person-photo" width="40" height="40" alt="Candidate Profile Picture" src="https://gravatar.com/avatar/b6d305a017cc572d47807d9e6812bef1.png?s=40&d=https%3A%2F%2Fcdn.greenhouse.io%2Fassets%2Fsilhouette-7fdf9a27e7e8acd6f7cad72986479543.png">
</td>
<td class="person-info-column" href="/people/34284587?application_id=43352812&src=search">
<p class="name">
Chew Bacca
<img class="email-candidate-icon" title="Email Chew" width="16" modal_path="/people/34284587/email_candidate_modal?application_id=43352812" src="https://cdn.greenhouse.io/assets/icons/email-fd1e71440bb47a93b13bccdbffa4d311.png" alt="Email">
</p>
</td>
<td class="job-info-column" href="/people/34284587?application_id=43352812&src=search">
<p class="job">Consulting Engineer </p>
<div class="status">
<a class="toggle-interviews" href="#">1 interview to schedule for Face to Face</a>
</div>
</td>
<td class="interview-kit-column" nofollow="true">
<div class="interview-kit-wrapper">
<span class="interview-kit-icon"></span><br>
<a modal_path="/people/34284587/applications/43352812/submit_feedback_options" class="submit-feedback-link" href="#">interview kit</a>
</div>
<label class="bulk-checkbox-wrapper">
<input class="bulk-checkbox" type="checkbox">
</label>
</td>
</tr>
<tr class="availability">
<td colspan="3" class="details name">
<div class="header">
<div class="left-col">
<span class="title closed no-expand">Availability</span>
<span class="state">
<div class="dropdown">
<button name="button" type="submit" id="quick_action_304014813" class="link-like-button" data-toggle="dropdown" aria-has-popup="true" aria-expanded="false">Not Requested</button>
<ul class="dropdown-menu" aria-labelledby="quick_action_304014813">
<li data-type="state" data-url="/people/availability/304014813/state" data-state="not_requested" class="dropdown-item" data-current-state="true">Not Requested</li>
<li data-type="state" data-url="/people/availability/304014813/state" data-state="requested" class="dropdown-item">Requested</li>
<li data-type="state" data-url="/people/availability/304014813/state" data-state="received" class="dropdown-item">Received</li>
<li data-type="state" data-url="/people/availability/304014813/state" data-state="confirmation_sent" class="dropdown-item">Confirmation Sent</li>
<li data-type="action" data-url="/people/availability/edit_modal/304014813?force=true" data-action="edit_availability" class="dropdown-item action-item">ENTER AVAILABILITY MANUALLY</li>
<li data-type="action" data-url="/people/availability/cofirm_modal/304014813?force=true" data-action="send_confirmation" class="dropdown-item action-item">SEND INTERVIEW CONFIRMATION</li>
</ul>
</div>
<span class="action-time"></span>
</span>
</div>
<span class="action">
<button name="button" type="submit" class="link-like-button availability-modal-open" modal_path="/people/availability/request_modal/304014813" data-modal-path="/people/availability/request_modal/304014813">Request Availability</button>
</span>
</div>
<div class="body">
<div class="times-container">
<div class="times proposed">
<div class="title">Suggested Times:</div>
<ul>
</ul>
</div>
<div class="times candidate">
<div class="title">
Chew is available at these times:
</div>
Not yet responded <button name="button" type="button" modal_path="/people/availability/edit_modal/304014813" class="link-like-button availability-edit-modal-open">Edit</button>
</div>
</div>
</div>
</td>
<td class="interview-kit-column"></td>
</tr>
<tr class="interview spicy" application_id="43352812" step_id="553192" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/553364/people/34284587?application_id=43352812" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Cultural Fit Interview
</td>
<td class="details">
<div class="wrapper">
<div class="interview-info">
Skipped <span href="/interviews/49710750/unskip" class="unskip-link">Unskip</span>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
<tr class="interview spicy" application_id="43352812" step_id="553193" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/553365/people/34284587?application_id=43352812" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Peer Panel Interview
</td>
<td class="details">
<div class="wrapper">
<div class="interview-info">
Skipped <span href="/interviews/49710751/unskip" class="unskip-link">Unskip</span>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
<tr class="interview spicy" application_id="43352812" step_id="553194" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/553366/people/34284587?application_id=43352812" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Case Study
</td>
<td class="details">
<div class="wrapper">
<div class="interview-info">
Skipped <span href="/interviews/49710752/unskip" class="unskip-link">Unskip</span>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
<tr class="interview spicy" application_id="43352812" step_id="553195" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/553367/people/34284587?application_id=43352812" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Executive Interview
</td>
<td class="details">
<div class="wrapper">
<div class="interview-info">
Skipped <span href="/interviews/49710753/unskip" class="unskip-link">Unskip</span>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
<tr class="interview spicy" application_id="43352812" step_id="4883928" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/4884061/people/34284587?application_id=43352812" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Challenge
</td>
<td class="details schedulable removable" modal_path="/interviews/schedule?application_id=43352812&interview_kit_id=4884061" modal_title="Consulting Engineer (Austin, New York City, Palo Alto)" nofollow="true" title="Schedule Interview">
<div class="wrapper">
<span href="/interviews/49710754/skip" class="x" title="Skip this interview"></span>
<span class="to-be-scheduled-icon"></span>
<div class="interview-info">
Schedule Interview
<div class="integration-buttons">
</div>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
<tr class="interview spicy" application_id="43352812" step_id="4883933" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/4884066/people/34284587?application_id=43352812" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Personality Assessment
</td>
<td class="details">
<div class="wrapper">
<div class="interview-info">
Skipped <span href="/interviews/49710755/unskip" class="unskip-link">Unskip</span>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
</tbody></table>
<table class="person show-interviews interviews-loaded" application="31024648" current-interview-stage-id="373842" candidate_hiring_plan="52610">
<tbody><tr class="basic-info clickable candidate">
<td class="photo-column" href="/people/5879170?application_id=31024648&src=search">
<img class="person-photo" width="30" height="40" alt="Candidate Profile Picture" src="https://prod-heroku.s3.amazonaws.com/people/photos/005/879/170/resized/imgres.jpg?AWSAccessKeyId=AKIAIK36UTOKQ5F2YNMQ&Expires=1495711223&Signature=GuPHCM1nw%2B2tC%2F44rHejCRvnsx0%3D">
</td>
<td class="person-info-column" href="/people/5879170?application_id=31024648&src=search">
<p class="name">
Jessica Alba
<span class="alert" title="Jessica Alba has been in Phone Interview for more than 14 days">Alert</span>
</p>
<p class="title">New York University</p>
</td>
<td class="job-info-column" href="/people/5879170?application_id=31024648&src=search">
<p class="job">Enterprise Account Executive (North America)</p>
<div class="status">
<a class="toggle-interviews" href="#">1 interview to schedule for Phone Interview</a>
</div>
</td>
<td class="interview-kit-column" nofollow="true">
<div class="interview-kit-wrapper">
<span class="interview-kit-icon"></span><br>
<a modal_path="/people/5879170/applications/31024648/submit_feedback_options" class="submit-feedback-link" href="#">interview kit</a>
</div>
<label class="bulk-checkbox-wrapper">
<input class="bulk-checkbox" type="checkbox">
</label>
</td>
</tr>
<tr class="availability">
<td colspan="3" class="details name">
<div class="header">
<div class="left-col">
<span class="title closed no-expand">Availability</span>
<span class="state">
<div class="dropdown">
<button name="button" type="submit" id="quick_action_210624650" class="link-like-button" data-toggle="dropdown" aria-has-popup="true" aria-expanded="false">Not Requested</button>
<ul class="dropdown-menu" aria-labelledby="quick_action_210624650">
<li data-type="state" data-url="/people/availability/210624650/state" data-state="not_requested" class="dropdown-item" data-current-state="true">Not Requested</li>
<li data-type="state" data-url="/people/availability/210624650/state" data-state="requested" class="dropdown-item">Requested</li>
<li data-type="state" data-url="/people/availability/210624650/state" data-state="received" class="dropdown-item">Received</li>
<li data-type="state" data-url="/people/availability/210624650/state" data-state="confirmation_sent" class="dropdown-item">Confirmation Sent</li>
<li data-type="action" data-url="/people/availability/edit_modal/210624650?force=true" data-action="edit_availability" class="dropdown-item action-item">ENTER AVAILABILITY MANUALLY</li>
<li data-type="action" data-url="/people/availability/cofirm_modal/210624650?force=true" data-action="send_confirmation" class="dropdown-item action-item">SEND INTERVIEW CONFIRMATION</li>
</ul>
</div>
<span class="action-time"></span>
</span>
</div>
<span class="action">
<button name="button" type="submit" class="link-like-button availability-modal-open" modal_path="/people/availability/request_modal/210624650" data-modal-path="/people/availability/request_modal/210624650">Request Availability</button>
</span>
</div>
<div class="body">
<div class="times-container">
<div class="times proposed">
<div class="title">Suggested Times:</div>
<ul>
</ul>
</div>
<div class="times candidate">
<div class="title">
Jessica is available at these times:
</div>
Not yet responded <button name="button" type="button" modal_path="/people/availability/edit_modal/210624650" class="link-like-button availability-edit-modal-open">Edit</button>
</div>
</div>
</div>
</td>
<td class="interview-kit-column"></td>
</tr>
<tr class="interview spicy" application_id="31024648" step_id="553218" stage_id="" style="">
<td colspan="2" rowspan="1" class="name" href="/guides/553390/people/5879170?application_id=31024648" title="View Interview Kit">
<span class="interview-kit-icon small"></span>Technical Phone Interview
</td>
<td class="details schedulable removable" modal_path="/interviews/schedule?application_id=31024648&interview_kit_id=553390" modal_title="Enterprise Account Executive (North America)" nofollow="true" title="Schedule Interview">
<div class="wrapper">
<span href="/interviews/23067896/skip" class="x" title="Skip this interview"></span>
<span class="to-be-scheduled-icon"></span>
<div class="interview-info">
Schedule Interview
<div class="integration-buttons">
</div>
</div>
</div>
</td>
<td class="interview-kit-column">
</td>
</tr>
</tbody></table>
There are multiple table classes(person show-interviews interviews-loaded). I want to extract class from class where text mathes or contains Challenge. I want to ignore other classes. This is what I have tried so far :
with open('Page_Source.html') as page_source:
soup=BeautifulSoup(page_source,'html.parser')
for table in soup.findAll('table',{'class':'person show-interviews interviews-loaded'}):
name=table.find('p',{'class':'name'}).find('a').text
#print name
#print table['application']
#print table['current-interview-stage-id']
job_title=table.find('p',{'class':'job'}).text
#print job_title
next_interview_details=table.find('a',{'class':'toggle-interviews'}).text
#print next_interview_details
for tr in table.findAll('tr',{'class':'interview spicy'}):
i=tr.find('td',text='Challenge')
print i
You can filter the desired table(s) by applying a filtering function where you check for Challenge substring to be present in the table's "text":
for table in soup.find_all(lambda tag: tag.name == 'table' and 'Challenge' in tag.get_text()):
print(table.get('class'))
Prints:
['person', 'show-interviews', 'interviews-loaded']
Ask BeautifulSoup to give you the list of tables. Then look at each table, asking whether it contains 'Challenge'. If it does then display the class attribute for that table.
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(open('temp.htm').read(),'lxml')
>>> tables = soup.findAll('table')
>>> for table in tables:
... if 'Challenge' in table.text:
... table.attrs['class']
...
['person', 'show-interviews', 'interviews-loaded']
EDIT: Response to comment. I haven't written the code as a filter this time because I wanted to make the logic more apparent.
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(open('temp.htm').read(),'lxml')
>>> tables = soup.findAll('table')
>>> for table in tables:
... '----->', table.attrs['class']
... target_tds = [_.parent for _ in table.findAll('span', attrs={'class': 'interview-kit-icon small'})]
... for target_td in target_tds:
... target_td.text.strip(), 'Skipped' in target_td.fetchNextSiblings()[0].text
...
('----->', ['person', 'show-interviews', 'interviews-loaded'])
('Cultural Fit Interview', True)
('Peer Panel Interview', True)
('Case Study', True)
('Executive Interview', True)
('Challenge', False)
('Personality Assessment', True)
('----->', ['person', 'show-interviews', 'interviews-loaded'])
('Technical Phone Interview', False)

Python Selenium - entering value in a text box

I am using python selenium to automate the attendance entry of our students. The contents in a attendance web page is form of table. There is a text box where we have mark 'A' or 'P'. The source code is as follows:
<form name="attendance1" action="/sjcet/attendance.php" method="POST">
<table style="width: 65%; margin: auto;">
<tr>
<th style="text-align: center;">Roll No.</th>
<th style="text-align: center;">PID</th>
<th style="text-align: center;">Student Name</th>
<th style="text-align: center;">Status</th>
<th style="text-align: center;">Any Comment</th>
</tr>
<tr style="text-align: center;">
<td style="text-align: center;"> <input name="roll_no[]" tabindex="0" size="3" type='text' value = '1' readonly='readonly' style="text-align: center;" /> </td>
<td style="text-align: center;"> <input name="pid[]" tabindex="0" size="10" type='text' value = 'EU1124021' readonly='readonly' style="text-align: center;" /> </td>
<td style="text-align: left;"> Abraham Ancy Chandy Anne</td>
<td style="text-align: center;">
<input size="3" name="status[]" type="text" onkeypress="return isNumberKey(event)" maxlength ="1" tabindex="1" style="text-align: center;" value='A' />
</td>
<td style="text-align: center;">
<input size="20" name="comment[]" type="text" />
</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: center;"> <input name="roll_no[]" tabindex="0" size="3" type='text' value = '2' readonly='readonly' style="text-align: center;" /> </td>
<td style="text-align: center;"> <input name="pid[]" tabindex="0" size="10" type='text' value = 'EU2134011' readonly='readonly' style="text-align: center;" /> </td>
<td style="text-align: left;"> Barabde Pranjal Sanjiv Sudha</td>
<td style="text-align: center;">
<input size="3" name="status[]" type="text" onkeypress="return isNumberKey(event)" maxlength ="1" tabindex="2"
style="text-align: center;" value='A' />
</td>
<td style="text-align: center;">
<input size="20" name="comment[]" type="text" />
</td>
</tr>
The code for the text box where we type 'P' or 'A' is as follows:
<input size="3" name="status[]" type="text" onkeypress="return isNumberKey(event)" maxlength ="1" tabindex="1"
style="text-align: center;" value='A' />
...
...
...
<input size="3" name="status[]" type="text" onkeypress="return isNumberKey(event)" maxlength ="1" tabindex="2"
style="text-align: center;" value='A' />
By default the value is 'A', I tried to enter the value 'P' using python selenium and the code I tried was:
driver.find_element_by_css_selector("input[tabindex='1']").send_keys('P')
I also tried
driver.find_element_by_xpath("//input[#tabindex='1']").send_keys('P')
But it is not changing the text to 'P', but the cursor is going to that text box. What might be the problem? Is it because of the 'onkeypress' event? Kindly help me with this, I am new to python selenium.
The code for isNumberKey(event) is as follows:
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if(charCode != 8){
if(charCode != 112)
{
if(charCode != 80)
{
if(charCode != 97)
{
if(charCode != 65)
{
return false;
}
}
}
}
}
return true;
}
You need to clean up the field first since there is a default A value there:
for elm in driver.find_elements_by_css_selector("input[name^=status]"):
elm.clear()
elm.send_keys('P')
Also, a quick and dirty solution could be to remove the onkeypress attribute:
for elm in driver.find_elements_by_css_selector("input[name^=status]"):
driver.execute_script("arguments[0].removeAttribute('onkeypress');", elm)
elm.send_keys('P')
First of all, your selector will work only for one student (the first) not for a list of students. Should be something like:
driver.find_elements_by_css_selector("input[name^='status']")
As for your problem, you might want to check what that javascript isNumberKey(event) is doing, it might be that it returns false when typing A or P

How to select radio buttons and submit a form

This is the HTML:
<form method="post" action="./xxxxx" name="form1">
<input type="hidden" name="requestKey" value="52032a76cf53340b07052fd143feddc4a9d8f18130c80ec86003ab56e0d91b36"/>
<input type="hidden" name="option" value="txnlist">
<input type="hidden" name="account" value='1336169999'>
<input type="hidden" name="app" value="D">
<input type="hidden" name="lockType" value="">
<p><span class="header2"> Statement options </span>
<table summary="" width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="20"></td>
<td width="20"><input type="radio" name="optDateFilter" value="1"></td>
<td>Transactions for the last 30 days</td>
<td></td>
</tr>
<tr>
<td width="20"></td>
<td width="20"><input type="radio" name="optDateFilter" value="2"></td>
<td>Transactions for the last 90 days</td>
<td></td>
</tr>
<tr>
<td width="20"> </td>
<td width="20"><input type="radio" name="optDateFilter" checked='checked' value="3" style="vertical-align: middle"></td>
<td>
<div>
<font style="vertical-align: middle;">Transactions from </font>
<script src='jquery/js/ui/min/jquery.ui.datepicker.min-1.8.10.js'></script>
<script type='text/javascript'>$(function() {$('#datepicker1').datepicker( { changeMonth : true, changeYear : true, dateFormat : 'dd/mm/yy', showOn: 'both', buttonImage: 'images/calendar.png', buttonImageOnly: true }); }); </script>
<input type='text' id='datepicker1' name='txtFromDate' size='11' maxlength='10' value='14/12/2012' onchange="checkFromDate(document.form1.txtFromDate.value);document.form1.optDateFilter[2].checked = true;">
<font style="vertical-align: middle;">to</font>
<script type='text/javascript'>$(function() {$('#datepicker2').datepicker( { changeMonth : true, changeYear : true, dateFormat : 'dd/mm/yy', showOn: 'both', buttonImage: 'images/calendar.png', buttonImageOnly: true }); }); </script>
<input type='text' id='datepicker2' name='txtToDate' size='11' maxlength='10' value='01/01/2013' onchange="checkToDate(document.form1.txtFromDate.value,document.form1.txtToDate.value);document.form1.optDateFilter[2].checked = true;">
</div>
</td>
<td><font style="font-size: 8pt; vertical-align: middle;"><i>(maximum date range 3 months)</i></font></td>
</tr>
</table>
<table summary="" cellpadding="1" cellspacing="1" border="0">
<tr>
<td width="20"> </td>
<td width="20">
<a href="javascript:if(document.form1.optDateFilter[2].checked==true){CheckAndSubmit(document.form1.txtFromDate.value,document.form1.txtToDate.value);}else{showOverlay();document.form1.submit();};">
<img src="images/proceed.gif" alt="Show the selected range of transactions" border="0" width="22" height="22" />
</a>
</td>
<td>
Show the selected range of transactions
</td>
</tr>
</table>
</form>
This is the code i have, and it is not working:
self.browser.select_form('form1')
self.browser.form.set_all_readonly(False)
self.browser['txtFromDate'] = '28/12/12'
self.browser['txtToDate'] = '01/01/13'
resp = self.browser.submit()
html = resp.read()
I figured that i had to do this
self.browser.select_form('form1')
self.browser['optDateFilter'] = ['2']
self.browser.form.find_control(name="txtFromDate", id="datepicker1").value = "13/10/12"
self.browser.form.find_control(name="txtToDate", id="datepicker2").value = "01/01/13"
resp = self.browser.submit()
mechanize has a strange quirk: since there can be multiple radio button elements in a HTML document with the same name it insists that you use a list as value, even though only a single radio button may be selected at any time. That means that you need to use this:
self.browser.form.find_control(name='optDateFilter').value = ['2']
The same holds for checkboxes where it makes more sense because a user is allowed to select multiple values.

Categories