Created
April 5, 2020 08:06
-
-
Save salgo60/951a68410db16e6929241bd73ad91659 to your computer and use it in GitHub Desktop.
Funkar inte hundra skall nog ha timeout eller kolla att sidan laddats
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
from builtins import type | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
driver = webdriver.Firefox() | |
start = 1 | |
endrange = 10000 | |
with open('breadfilecounty.txt','w') as filehandlecounty: | |
with open('breadfilekommun.txt','w') as filehandle: | |
for page in range(start,endrange): | |
#print(page) | |
url = "https://www.hembygd.se/shf/plats/" + str(page) | |
print(url) | |
driver.get(url) | |
# assert "Sveriges Hembygdsförbund" in driver.title | |
time.sleep(4) | |
elem = driver.find_elements_by_css_selector('ol.breadcrumb') | |
# print (elem) | |
for el in elem: | |
print(el.text) | |
if el.text[-6:] in "kommun": | |
line = str(page) + ": " + el.text.replace("Sverige","") | |
print("\t" + line) | |
filehandle.writelines(line ) | |
filehandle.writelines('\n') | |
if el.text[-3:] in "län": | |
line = str(page) + ": " + el.text.replace("Sverige","") | |
print("\t" + line) | |
filehandlecounty.writelines(line) | |
filehandlecounty.writelines('\n') | |
assert "No results found." not in driver.page_source | |
#time.sleep(5) | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment