Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:53:57+00:00 2026-05-27T01:53:57+00:00

I have a list of words, in Python I need to loop through each

  • 0

I have a list of words, in Python I need to loop through each word and check if the word is on a website.

Currently, this is a snippet of what I have (relating to this problem):

words = ['word', 'word1', 'word2']
site = urllib.request.urlopen(link)
for word in words:
    if word in site:
       print(word)
    else:
       print(word, "not found")

I have a list of words, I open the site, and I loop through each word checking for the word in the site. Note that I am using a website with all those words found on it (I set it up myself and I can verify it works) and the link is the url of the website.

The problem is, I always go to “word not found”, and it never seems to find the words on the website.

What’s wrong with the code? It seems to be a semantics error, because the syntax works fine, and there are no exceptions thrown (although in my final I do have exception handling, but it will still report if exceptions are thrown anyways).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:53:58+00:00Added an answer on May 27, 2026 at 1:53 am

    The urlopen() function returns a “file-like object”. In order to read the data, you must call read():

    site = urllib.request.urlopen(link).read()
    

    There are other ways to read the data too, but this is a simple way to load the whole page data into memory for quick searching.

    The reason your code worked as written is because a file-like object is also iterable, which means it can be used with the in operator. But it wasn’t doing what you wanted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of words. I type in a word misspelled. Can I query
Let's say I have a list of words, something like this: ['The', 'Quick', 'Brown',
I have some text i need to filter out a list of bad words
I have a VBA Word Macro that gets words from .txt list and color
I have some loop on the page and need list item depending from loop
I need to have all 6 letter Latin words in a list. I would
I have a list of input words separated by comma. I want to sort
I have quite a large list of words in a txt file and I'm
I have two files which both contain a list of words. Is there an
I have a string which is basically a list of words delimited by commas.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.