I've written a script in python to parse the name, tweets, following and follower of those people available in view all section in my profile page of twitter. My scraper is able to parse those aforesaid fields flawlessly. Any input on the improvement of my parser will be highly appreciated. Here is what I've written:
from selenium import webdriver
import time
def browsing_pages():
driver = webdriver.Chrome()
driver.get('https://twitter.com/?lang=en')
driver.find_element_by_xpath('//input[@id="signin-email"]').send_keys('username')
driver.find_element_by_xpath('//input[@id="signin-password"]').send_keys('password')
driver.find_element_by_xpath('//button[@type="submit"]').click()
time.sleep(5)
#Clicking the viewall link
driver.find_element_by_xpath("//small[@class='view-all']//a[contains(@class,'js-view-all-link')]").click()
time.sleep(5)
for links in driver.find_elements_by_xpath("//div[@class='stream-item-header']//a[contains(@class,'js-user-profile-link')]"):
scraping_docs(links.get_attribute("href"))
#tracking down each profile links under viewall section
def scraping_docs(item_link):
driver = webdriver.Chrome()
driver.get(item_link)
# gleaning information of each profile holder
for prof in driver.find_elements_by_xpath("//div[@class='route-profile']"):
name = prof.find_elements_by_xpath(".//h1[@class='ProfileHeaderCard-name']//a[contains(@class,'ProfileHeaderCard-nameLink')]")[0]
tweet = prof.find_elements_by_xpath(".//span[@class='ProfileNav-value']")[0]
following = prof.find_elements_by_xpath(".//span[@class='ProfileNav-value']")[1]
follower = prof.find_elements_by_xpath(".//span[@class='ProfileNav-value']")[2]
print(name.text, tweet.text, following.text, follower.text)
driver.quit()
browsing_pages()