I have two prints that I want to write to a single CSV File into Column A and Column B
My problem is when I print both(first and second print) at the end , I get only an element, multiple times I guess because it's not inside a loop or so.
print((text), (link[0:-9]))
Result :
LMFCIIC PWFERT-BK
LMFCIIC PMFEP-BK
LMFCIIC LMF8CC-BL
LMFCIIC PMFEP-GY
LMFCIIC ASPCP-NV
LMFCIIC LWBASK-PK
LMFCIIC LWBATA-PK
LMFCIIC LWBATOP-PK
LMFCIIC LMF8CC-RD
My first print looks like this : And I want to print it to Column A
PWFERT-BK
PMFEP-BK
LMF8CC-BL
PMFEP-GY
ASPCP-NV
LWBASK-PK
LWBATA-PK
LWBATOP-PK
LMF8CC-RD
My Second print looks like this : And I want to print it to Column B
LMFCIIC
LWBASK
LWBATA
LWBATOP
LMFCIIC
Here is my full code :
from bs4 import BeautifulSoup
from selenium import webdriver
import html5lib
import time
import requests
driver_path = '/usr/local/bin/chromedriver 2'
driver = webdriver.Chrome(driver_path)
driver.implicitly_wait(10)
driver.get('https://www.tenniswarehouse-europe.com/zzz/producttracker_bl.html?ccode=SWIMG030')
try:
iframe = driver.find_elements_by_tag_name('iframe')
for i in range(0, len(iframe)):
f = driver.find_elements_by_tag_name('iframe')[i]
driver.switch_to.frame(i)
# your work to extract link
text = driver.find_element_by_tag_name('body').text
text = text.replace("Code: ","")
text = text.replace("No Copy Images to TW Server","")
print(text)
driver.switch_to_default_content()
finally:
driver.quit()
resp = requests.get('https://www.tenniswarehouse-europe.com/zzz/producttracker_bl.html?ccode=SWIMG030')
soup = BeautifulSoup(resp.text,"lxml")
for frame in soup.findAll('img'):
link = (frame['src'])
link = link.split('=')[1]
print ((link[0:-9]))
- I used www.example.com because the link is not accessible out of my network