ADD get fileattribute, file basename
This commit is contained in:
parent
656ed78288
commit
a479e1586f
@ -44,27 +44,31 @@ def call_website(url,interactive=False):
|
|||||||
|
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
print(driver.title)
|
print(driver.title)
|
||||||
elements = driver.find_elements(By.XPATH,'//a[contains(@href,"Rufzeichen")]')
|
# elements = driver.find_elements(By.XPATH,'//a[contains(@href,"Rufzeichen")]')
|
||||||
|
elements = driver.find_elements(By.PARTIAL_LINK_TEXT,"Rufzeichen")
|
||||||
|
|
||||||
if elements:
|
if elements:
|
||||||
element = elements[0]
|
element = elements[0]
|
||||||
filename = element.click()
|
href = element.get_attribute('href')
|
||||||
|
filename = element.click() # take the first one
|
||||||
else:
|
else:
|
||||||
print('Sorry, no Link containing "Rufzeichen" found.')
|
print('Sorry, no Link containing "Rufzeichen" found.')
|
||||||
driver.close()
|
driver.close()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
print(element.text)
|
print(element.text)
|
||||||
print()
|
# print(href)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
driver.close()
|
driver.close()
|
||||||
|
return os.path.basename(href)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# call_description()
|
# call_description()
|
||||||
args = call_parser()
|
args = call_parser()
|
||||||
try:
|
try:
|
||||||
filename = call_website(**vars(args))
|
filename = call_website(**vars(args))
|
||||||
|
print(f'File name: {filename}')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Error: {}'.format(e), file=sys.stderr)
|
print('Error: {}'.format(e), file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user