Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97756

If Statment in Python while Scraping

$
0
0

I want to add if statement there:

if website_link and phone is not found than write N,N

This Script is typing if website link is not found it type N and if phone is not found it type N

I Want Also Add This:

If Website And Phone is not found Type N,N

Here is my Code:

from selenium import webdriver 
import csv
import pandas
import itertools

with open("sans.csv",'r') as s:
    s.read()

driver = webdriver.Firefox()

url = 'https://www.yelp.com/biz/konomama-san-francisco?osq=Restaurants'

driver.get(url)
website_link = driver.find_elements_by_css_selector('.text--offscreen__373c0__1SeFX+ .link-size--default__373c0__1skgq')

phone = driver.find_elements_by_css_selector('.text--offscreen__373c0__1SeFX+ .text-align--left__373c0__2pnx_')

items = len(website_link)
with open("sans.csv", 'a',encoding="utf-8") as s:
    for combination in itertools.zip_longest(website_link, phone):
         s.write(f'{combination[0].text if combination[0] else "N"}, {combination[1].text if combination[1] else "N"}\n')

driver.close()

print("Done")

Thanks!


Viewing all articles
Browse latest Browse all 97756

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>