Created
November 9, 2019 05:30
-
-
Save viggy28/574f923dffae73d350ecdbcefa656631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# header file imported | |
from urllib import urlopen | |
from bs4 import BeautifulSoup | |
from selenium import webdriver | |
# give the location of chromedrive installed on your machine. | |
# path = r'C:\\Users\\gaurav\\Desktop\\Chromedriver' | |
# ref: https://www.tutorialspoint.com/python_web_scraping/python_web_scraping_dynamic_websites.htm | |
path="" | |
driver = webdriver.Chrome(executable_path = path) | |
# creating a file name | |
file = "Details.csv" | |
f = open(file, "w") #open the file | |
Headers = "Name,Location\n" #heading part | |
f.write(Headers) #inserting the heading | |
# range = [0 to 2] | |
# loop for multi page open | |
for i in range(0,3): | |
url = "https://stackoverflow.com/users?page=()&tab=reputation&filter=week".format(i) | |
driver.get(url) | |
soup = BeautifulSoup(driver.page_source,'html.parser') | |
print("soup") | |
# soup now list all data including tags such as python, mysql | |
print(soup) | |
# finding the name of the user inside the class file | |
Title = soup.find_all("div", {"class":"user-details"}) | |
print(len(Title)) #total lenth of the user in the page | |
# loop for getting the name | |
for i in Title: | |
try: | |
name = i.find('a').get_text() | |
location = i.find('span', class_ ='user-location') | |
# print(name) | |
# print(locatin) | |
name_list = (name) | |
# location_list = (location) | |
f.write(name_list) | |
# f.write(location_list) | |
f.write("\n") | |
except: AttributeError | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment