Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get html body of URL
#7
Here a example with Selenium,it's not the most easy page to start with if new to this.
If you can find in info in the json return as @buran show,
then that is fine and fast way as it only requires Requests with a get call and catch response .json().
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time

#--| Setup
options = Options()
#options.add_argument("--headless")
#options.add_argument("--window-size=1980,1020")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
url = "https://www.sreality.cz/hledani/pronajem/byty/praha?velikost=1%2B1"
browser.get(url)
time.sleep(3)
# Use BeautifulSoup
soup = BeautifulSoup(browser.page_source, 'lxml')
title = soup.find('h1', class_="page-title list-title ng-binding")
print(title.text)
print('-' * 40)
# Use Selenium
info = browser.find_elements_by_xpath("//div[@class='dir-property-list']//div[1]//div[1]//div[1]")
print(info[0].text)
Output:
Byty 1+1 k pronájmu Praha ---------------------------------------- Pronájem bytu 1+kk 35 m² Praha 5 - Smíchov 14 000 Kč za měsíc
Reply


Messages In This Thread
Get html body of URL - by rama27 - Aug-02-2020, 04:14 PM
RE: Get html body of URL - by Larz60+ - Aug-02-2020, 09:01 PM
RE: Get html body of URL - by buran - Aug-03-2020, 07:00 AM
RE: Get html body of URL - by rama27 - Aug-03-2020, 09:00 AM
RE: Get html body of URL - by Larz60+ - Aug-03-2020, 09:32 AM
RE: Get html body of URL - by buran - Aug-03-2020, 10:41 AM
RE: Get html body of URL - by snippsat - Aug-03-2020, 02:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [BeautifulSoup] Find </body>? Winfried 3 1,428 Jul-21-2023, 11:25 AM
Last Post: Gaurav_Kumar
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,746 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,417 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  Is it possible to perform a PUT request by passing a req body instead of an ID ary 0 1,863 Feb-20-2019, 05:55 AM
Last Post: ary
  In CSV, how to write the header after writing the body? Tim 18 14,892 Jan-06-2018, 01:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020