I am new to beautiful soup / selenium in python, I am trying to get contact / emails from a list of URLs. URLs:
listOfURLs=['https://oooo.com/Number=xxxxx', 'https://oooo.com/Number/yyyyyy', 'https://oooo.com/Number/zzzzzz']
HTML I am parsing:
<div class="row classicdiv" id="renderContacInfo">
<div class="col-md-2" style="word-break: break-word;">
<h6>Contact</h6>
<h5>Israa S</h5>
</div>
<div class="col-md-2" style="word-break: break-word;">
<h6>Email</h6>
<h5>israa.s@xxxx.com <br/>
</h5>
</div>
<div class="col-md-2" style="word-break: break-word;">
<h6>Alternate Email</h6>
<h5></h5>
</div>
<div class="col-md-2">
<h6>Primary Phone</h6>
<h5>1--1</h5>
</div>
<div class="col-md-2">
<h6>Alternate Phone</h6>
<h5>
</h5>
</div>
</div>
I am trying to loop the list of URLs, but I am only able to get the soup
from the first url in the list.
The code written:
driver = webdriver.Chrome(chrome_driver_path)
driver.implicitly_wait(300)
driver.maximize_window()
driver.get(url)
driver.implicitly_wait(30)
content=driver.page_source
soup=BeautifulSoup(content,'html.parser')
contact_text=soup.findAll("div",{"id":"renderContacInfo"})
output1=''
output2=''
print(contact_text)
time.sleep(100)
for tx in contact_text:
time.sleep(100)
output1+=tx.find(text="Email").findNext('h5').text
output2+=tx.find(text="Contact").findNext('h5').text
My questions:
- How to iterate loop through the list or URLs I have?
- How to filter the Email and contact from the
soup html
. - Expected output:
URL Contact Email
https://oooo.com/Number=xxxxx xxxxxxxx xxxx@xxx.com
https://oooo.com/Number=yyyyy yyyyyyyy yyyy@yyy.com