0

I'd like to clicks all links which contain some specific words, links (hrefs) are like:

what is blue

how to mix red with yellow

is pink dress good?

They are all links which I can click, but I only want to click titles with word 'blue' and 'pink', else, next link, so I do: but it just says no links contain the word

it is like a list = ['what is blue','how to mix red with yellow','is pink dress good?'] and I want to access all elements and check if element in list = ['blue','pink'] is it in it

list = ['what is blue','how to mix red with yellow','is pink dress good?']
list2 = ['blue','pink'] 

if any elements in list2 is also in list(hrefs), click it, else ignore it

Thank you for your time in advance!

word = {'blue','pink'}
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath('')] 
keywords= [keyword.get_attribute('innerHTML') for keyword in driver.find_elements_by_xpath('')] 
for line in keywords:
    if set(words).intersection(line.split(",")):
       print("in it")
       driver.get(link)

also I tried, I want like title contains sth like blue

keyword = driver.find_elements_by_xpath('//*[contains(@title, id)]')

the html looks like

<a href="/zbscbzw/isinbm/202101/6b958a0fae1f497f8ec65b60d64120d9.shtml" target="_blank" title="new issue blue thing">New issue blue thing</a>
Joyce
  • 435
  • 4
  • 13
  • Does this answer your question? [Check if multiple strings exist in another string](https://stackoverflow.com/questions/3389574/check-if-multiple-strings-exist-in-another-string) – Arundeep Chohan Jan 21 '21 at 06:43
  • think not, as the hrefs are a list with ',' spilt, not just a_string = "A string is more than its parts!" – Joyce Jan 21 '21 at 06:48
  • Hey, sorry to bother , I want add this to the last question's solution,find_elements_by_xpath('//*[contains(@title, keyword)]'): title contains 'keyword' list and also in date 1-20, how could I achieve it? – Joyce Jan 21 '21 at 07:46

1 Answers1

0

You can probably make it simpler than this. Basically check if blue is in the string of list1 for each word.

list1 = ['what is blue','how to mix red with yellow','is pink dress good?']
list2 = ['blue','pink'] 
for l in list1:
    for x in list2:
        if x in l:
            print(x)
        else:
            print('No')
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32