Z
Z
zlodiak2019-05-22 11:47:58
Python
zlodiak, 2019-05-22 11:47:58

How to click on an element?

Please tell me how you can click on an element on the page. I parsed a certain page using beautifulSoup. In the resulting html, I found an element that the parser must click on to open another page (which I will parse too)
I don't understand what command to use to simulate a click. Here is my code that finds the element in the DOM tree to click on:

import requests
from bs4 import BeautifulSoup
from mechanize import Browser

url = 'https://www.avito.ru/saransk/kvartiry/1-k_kvartira_47_m_25_et._1610295577'
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36'}
browser = Browser()

page_html = requests.get(url, headers=headers).text

soup = BeautifulSoup(page_html, 'lxml')

img_obj = soup.find('div', {'class': 'gallery-imgs-container'}).find('img')

img_url = 'https:' + img_obj['src']

print(img_url)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jo, 2019-05-22
@zlodiak

And what's the problem? You have in your hands the img_url = 'https:' + img_obj['src']url by which you can load the page EXACTLY the same as the previous one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question