from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Chrome will run in a virtual display.
# you will not see the browser.
browser = webdriver.Chrome()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
//*[@role='most_interest']//a[contains(text(), 'изнутри') or contains(text(), 'нативного')]
(//p[@class='message-text'])[last()]
# Click the link to activate the alert
driver.find_element(By.LINK_TEXT, "See a sample confirm").click()
# Wait for the alert to be displayed
wait.until(expected_conditions.alert_is_present())
# Store the alert in a variable for reuse
alert = driver.switch_to.alert
# Store the alert text in a variable
text = alert.text
# Press the Cancel button
alert.dismiss()
from selenium.webdriver.common.by import By
element = driver.find_element(By.XPATH, xpath)
driver.findElementsByClassName("className");
driver.findElementsByCssSelector(".className");
driver.findElementsById("elementId");
driver.findElementsByLinkText("linkText");
driver.findElementsByName("elementName");
driver.findElementsByPartialLinkText("partialText");
driver.findElementsByTagName("elementTagName");
driver.findElementsByXPath("xPath");
driver.findElements(By.className("className"));
driver.findElements(By.cssSelector(".className"));
driver.findElements(By.id("elementId"));
driver.findElements(By.linkText("linkText"));
driver.findElements(By.name("elementName"));
driver.findElements(By.partialLinkText("partialText"));
driver.findElements(By.tagName("elementTagName"));
driver.findElements(By.xpath("xPath"));
from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, xpath)
# Xpath надо написать самому
iframe = driver.find_element_by_xpath("//iframe")
driver.switch_to.frame(iframe)
driver.switch_to.default_content()
import requests
params = {
'name': 'Иванов Иван Иванович',
'numberOrInn': '1111111111',
}
response = requests.get('https://www.rgs.ru/api/agents/checkAgent', params=params)
# {"Status":"NotFound","ErrorCorrelationIds":[],"ErrorCode":null}
print(response.text)
table = driver.find_element_by_xpath('//div[@class="table"]')
rows = table.find_elements_by_xpath('//div')
for row in rows:
print(row.text())
rows = driver.find_element_by_xpath('//div[@class="table"]//div')
for row in rows:
print(row.text())
items = node.find_elements_by_xpath('xpath')
for item in items:
print(item.get_attribute('href'))
timedelta(days=REMOVE_DATA_OLDER_THAN_DAYS)
timedelta(minutes=REMOVE_DATA_OLDER_THAN_MINUTES)
pip install .
, находясь в корневой директории репозитория//*[@class='testCard']/a
def parse(self):
self.go_to_questsions_page()
slide_elems = self.driver.find_elements_by_class_name("testCard")
f = open("text.txt", "w")
f.write(str(slide_elems))
for el in slide_elems:
print(el.get_attribute('href'))
elements = driver.find_elements_by_css_selector('.new-posts .post-item a')
page_urls = [element.get_attribute('href') for element in elements]
for url in page_urls:
driver.get(url)
pip install selenium-wire
from seleniumwire import webdriver
options = {
'proxy': {
'http': 'http://username:password@host:port',
'https': 'https://username:password@host:port',
'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
}
}
driver = webdriver.Firefox(seleniumwire_options=options)
Такой вариант возможен?
Или же можно ли использовать python и javascript?