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 9222225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:46:59+00:00 2026-06-18T03:46:59+00:00

EDIT:(SOLVED) When I am reading the values in from my file a newline char

  • 0

EDIT:(SOLVED) When I am reading the values in from my file a newline char is getting added onto the end.(\n) this is splitting my request string at that point.
I think it’s to do with how I saved the values to the file in the first place. Many thanks.

I have I have the following code:

results = 'http://www.myurl.com/'+str(mystring)
print str(results)
request = urllib2.Request(results)
request.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)')
opener = urllib2.build_opener()
text = opener.open(request).read()

Which is in a loop.
after the loop has run a few times str(mystring) changes to give a different set of results.
I can loop the script as many times as I like keeping the value of str(mystring) constant but every time I change the value of str(mystring) I get an error saying no host given when the code tries to build the opener.

opener = urllib2.build_opener()

Can anyone help please?

TIA,

Paul.

EDIT:

More code here…..

import sys
import string
import httplib
import urllib2
import re
import random
import time


def StripTags(text):
    finished = 0
    while not finished:
        finished = 1
        start = text.find("<")
        if start >= 0:
            stop = text[start:].find(">")
            if stop >= 0:
                text = text[:start] + text[start+stop+1:]
                finished = 0
    return text
mystring="test"

d={}

    with open("myfile","r") as f:
        while True:
            page_counter=0
            print str(mystring)

            try:
                while page_counter <20:
                    results = 'http://www.myurl.com/'+str(mystring)
                    print str(results)
                    request = urllib2.Request(results)
                    request.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)')
                    opener = urllib2.build_opener()
                    text = opener.open(request).read()
                    finds = (re.findall('([\w\.\-]+'+mystring+')',StripTags(text)))
                    for find in finds:
                        d[find]=1
                        uniq_emails=d.keys()
                    page_counter = page_counter +1
                    print "found this " +str(finds)"
                    random.seed()
                    n = random.random()
                    i = n * 5
                    print "Pausing script for " + str(i) + " Seconds" + ""
                    time.sleep(i)
                mystring=next(f)
            except IOError:
                print "No result found!"+""
  • 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-06-18T03:47:01+00:00Added an answer on June 18, 2026 at 3:47 am

    In the while loop, you’re setting results to something which is not a url:

    results = ‘myurl+str(mystring)’

    It should probably be results = myurl+str(mystring)

    By the way, it appears there’s no need for all the casting to string (str()) you do:
    (expanded on request)

    • print str(foo): in such a case, str() is never necessary. Python will always print foo's string representation
    • results = 'http://www.myurl.com/'+str(mystring). This is also unnecessary; mystring is already a string, so 'http://www.myurl.com/' + mystring would suffice.
    • print "Pausing script for " + str(i) + " Seconds". Here you would get an error without str() since you can’t do string + int. However, print "foo", 1, "bar" does work. As do print "foo %i bar" % 1 and print "foo {0} bar".format(1) (see here)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: solved, look below for my solution. first of all, this is my very
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
edit This question is solved! Having something weird. I'm using html { font-size: 100%
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
MAJOR EDIT: Problem was solved after reading Will Dean's comment. The original question is
edit: On odd change that someone is reading this, I'd like to add one
EDIT: Paul has solved this one below. Thanks! I'm trying to resample (upscale) a
EDIT: Problem solved. It was my reading that was incorrect, not the SQL :p
The problem I have is reading in multiple lines of integers from a file
Edit: [Solved] : It seems that the getTableCellRendererComponent of the CustomTableCellRenderer is called every

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.