0

I am still handling with a view problems. I am finally able to load the whole page with a view window.scrollBy(..) commands...

The problem I am facing now is that I would like to filter all headlines out of a text. The text I would like to screen is shown with this command:

[Code]

main = driver.find_element_by_id("mrt-node-quoteNewsStream-0-Stream")  

print(main.text)

That works well and all the result is shown. Within these results I am now wanna filter, as mentioned above all headlines. This should work wit the following code:

articles = main.find_elements_by_tag_name("mrt-node-quoteNewsStream-0-Stream") # li
for mrt-node-quoteNewsStream-0-Stream in articles:
    header = article.find_element_by_class_name("M(0)")
    print(header.text)

Unfortunately it shows me the following syntax error message:

File "", line 7
for mrt-node-quoteNewsStream-0-Stream in articles:
^
SyntaxError: can't assign to operator

Line 7 is the one with the following one:

for mrt-node-quoteNewsStream-0-Stream in articles:

Any help is highly appreciated. Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bebbi
  • 1
  • 3
  • `M(0)` is a dynamic class value. Update the question with the text based HTML. – undetected Selenium Jan 07 '21 at 20:02
  • thx for the input. But does the programm not have a problem line 7, the change you have mentioned would be in line 8. Does that make sense? (I am a beginner...) – Bebbi Jan 07 '21 at 20:09

1 Answers1

1

This line of code returns a list of elements:

articles = main.find_elements_by_tag_name("mrt-node-quoteNewsStream-0-Stream")

So articles is a list of WebElement and each of them looks like:

<selenium.webdriver.remote.webelement.WebElement (session="04a9fac269c3a9cb724cc72769aed4e0", element="1b8ee8d0-b26a-4c67-be10-615286a4d427")>

As per your second set of code trials, mrt-node-quoteNewsStream-0-Stream is the tag_name and you must not look for the tag_name within the element.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thx, for your answer! Exactly I would like to return a list with all the headlines. If I don't need to look for the tag_name, what else do I have to look for? – Bebbi Jan 07 '21 at 20:27
  • @Bebbi This sounds like an [X-Y problem](http://xyproblem.info/). Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do? Feel free raise a new question as per your new requirement? Stackoverflow contributors will be happy to help you out. – undetected Selenium Jan 07 '21 at 20:31
  • I am trying to get all the headlines. I've copied the part where the healines are in: So Articles should list me all the headlines, here for example the headline is "The Most Important Chinese Invention Ever!" The code on the page is as follows The Most Important Chinese Invention Ever! – Bebbi Jan 07 '21 at 20:36