This the the element that I am trying to find:
tbody ng-repeat="ut in vm.unitList | filter: (leaseLength: (vm.weekOption.value I l
"')}">…</tbody>
**Xpath - //*[@id="no-more-tables"]/tbody**
And this is my code:
driver.get(url)
[enter image description here][1]
property_name = driver.title
print('Property =====',property_name)
rooms = driver.find_elements(By.XPATH, '//*[@id="no-more-tables"]/tbody')
print (len(rooms))
The length of rooms are coming 0 even though I gave the correct xpath. Ideally it should come 5
CodePudding user response:
Data in that page is being loaded dynamically by Javascript, after loading the html. The following code will (remove the complexities of selenium and) get you the data you're after:
import requests
import pandas as pd
s = requests.Session()
data = {"route":"unitlist","command":"","data":"{\"list\":{\"filter\":{\"propertyNoFilter\":\"PR0170000\",\"dateFilter\":\"03/09/2022\"}}}"}
r = s.get('https://www.hellostudent.co.uk/student-accommodation/stoke/caledonia-mills/')
r = s.post('https://rooms.hellostudent.co.uk/DynamicsNav/Call', data=data)
# print(r.json()['list']['property'])
df = pd.DataFrame(r.json()['list']['property'])
print(df)
Result:
unitType unitSubType unitDescription noOfUnits mainPropertyNo startDate endDate leaseLength pricePerWeek biannualAvailable termPaymentAvailable features
0 SHAPT SHAPT-Q4-B4-ES Silver 4-Bed Apartment Ensuite 0 PR0170000 03/09/22 25/08/23 51 89.00 false true None
1 SHAPT SHAPT-Q4-B3-ES Silver 3-Bed Apartment Ensuite 12 PR0170000 03/09/22 25/08/23 51 93.00 false true None
2 SHAPT SHAPT-Q4-B2-ES Silver 2-Bed Apartment Ensuite 7 PR0170000 03/09/22 25/08/23 51 115.00 false true None
3 STUDIO STUDIO-Q4 Silver Studio 1 PR0170000 03/09/22 25/08/23 51 153.00 false true None
4 STUDIO STUDIO-Q3 Gold Studio 0 PR0170000 03/09/22 25/08/23 51 169.00 false true None