Answers for "python selenium scraper"

10

selenium webdriver python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
Posted by: Guest on April-10-2020
1

python selenium web scraping example

#Python example - use chrome driver to open google url and enter into search bar "Why is python so awesome"

#required imports
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#open driver
PATH_TO_DRIVER = './chromedriver'
driver = webdriver.Chrome(executable_path=PATH_TO_DRIVER)

#launch url using driver
driver.get('https://google.com')

#find element to manipulate e.g. by element name. 'q' is the element name of the google search bar
element = driver.find_element_by_name('q')

#write text into search bar
element.send_keys('Why is python so awesome')

#simulates 'Enter' key
element.send_keys(Keys.ENTER)
Posted by: Guest on August-23-2020
0

python selenium facebook scraper

import time
import re
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
 
usr = "<your_facebook_email_address>"
pwd = "<your_facebook_password>"
 
url = "https://mobile.facebook.com/story.php?story_fbid=10156391722455952&id=157851205951"
driver = webdriver.Chrome('/Users/zero/Documents/GitHub/SentimentAnalysis/chromedriver')
driver.get(url)
 
time.sleep(1)
if driver.find_element_by_xpath('//*[@id="viewport"] /div/div[3] /div/div[2] 
/div/a'):
   driver.find_element_by_xpath('//*[@id="viewport"] /div/div[3] /div/div[2] 
 
 
 
 
 
 
 
 
 
 
 
 
 
/div/a').click()
 
elem = driver.find_element_by_id("m_login_email")
elem.send_keys(usr)
 
elem = driver.find_element_by_id("m_login_password")
elem.send_keys(pwd)
 
elem.send_keys(Keys.RETURN)
 
hasLoadMore = True
while hasLoadMore:
    time.sleep(1)
    try:
        if driver.find_element_by_xpath('//*[@id="viewport"] /div/div[4] /div/div/div/div/div/div[2] /div/div/div[5] /*[@class="async_elem"] 
/a'):
            driver.find_element_by_xpath('//*[@id="viewport"] /div/div[4] /div/div/div/div/div/div[2] /div/div/div[5] /*[@class="async_elem"] 
 
 
 
/a').click()
    except:
        hasLoadMore = False
 
users_list = [] 
 
 
 
 
 
 
 
users = driver.find_elements_by_class_name('_2b05')
 
for user in users:
    users_list.append(user.text)
     
i = 0
texts_list = [] 
 
 
 
 
texts = driver.find_elements_by_class_name('_2b06')
 
for txt in texts:
    texts_list.append(txt.text.split(users_list[i] 
 
 
 
 
 
))
    i += 1
    comments_count = len(users_list)
 
 
for i in range(1, comments_count):
    user = users_list[i] 
 
    text = texts_list[i] 
 
 
    print("User ",user)
    print("Text ",text)
Posted by: Guest on November-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language