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

  • Home
  • SEARCH
  • 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 9070147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:36:49+00:00 2026-06-16T17:36:49+00:00

I am trying to write some data to csv file by checking some condition

  • 0

I am trying to write some data to csv file by checking some condition as below

I will have a list of urls in a text file as below

urls.txt

www.example.com/3gusb_form.aspx?cid=mum
www.example_second.com/postpaid_mum.aspx?cid=mum
www.example_second.com/feedback.aspx?cid=mum

Now i will go through each url from the text file and read the content of the url using urllib2 module in python and will search a string in the entire html page. If the required string founds i will write that url in to a csv file.

But when i am trying to write data(url) in to csv file,it is saving like each character in to one coloumn as below instead of saving entire url(data) in to one column

h   t   t   p   s   :   /   /   w   w   w...... 

Code.py

import urllib2
import csv

search_string = 'Listen Capcha'

html_urls = open('/path/to/input/file/urls.txt','r').readlines()
outputcsv = csv.writer(open('output/path' + 'urls_contaning _%s.csv'%search_string, "wb"),delimiter=',', quoting=csv.QUOTE_MINIMAL)
outputcsv.writerow(['URL'])

for url in html_urls:
    url = url.replace('\n','').strip()
    if not len(url) == 0:
        req = urllib2.Request(url)
        response = urllib2.urlopen(req)
        if str(search_string) in response.read():
            outputcsv.writerow(url)

So whats wrong with the above code, what needs to be done in order to save the entire url(string) in to one column in a csv file ?

Also how can we write data to a text file as above ?

Edited

Also i had a url suppose like http://www.vodafone.in/Pages/tuesdayoffers_che.aspx ,
this url will be redirected to http://www.vodafone.in/pages/home_che.aspx?cid=che in browser actually, but when i tried through code as below it is same as the above given url

import urllib2, httplib

httplib.HTTPConnection.debuglevel = 1  
request = urllib2.Request("http://www.vodafone.in/Pages/tuesdayoffers_che.aspx")
opener = urllib2.build_opener()
f = opener.open(request)
print f.geturl()

Result

http://www.vodafone.in/pages/tuesdayoffers_che.aspx?cid=che 

So finally how to catch the redirected url with urllib2 and fetch the data from it ?

  • 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-16T17:36:50+00:00Added an answer on June 16, 2026 at 5:36 pm

    Change the last line to:

                outputcsv.writerow([url])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write some simple code which will read a text file
I am trying to create a csv file of some data. I have wrote
I'm trying to write some data to a CSV file from TCL script with
I am trying to write some data from these vectors onto text files. When
I have been trying to write some code in Scala to read a file
I am trying to write an AngularJS resource module that will post some data
I have the following JSON: {COLUMNS:[ID,FIRSTNAME],DATA:[[1,Steve],[2,Jim],[3,Bill],[4,Tony]]} I am trying to write some jQuery that
I'm trying to write some simple C# code that will select some data from
I'm trying to assemble a CSV file from some DB data and send it
I'm trying to write a program that will write some data to a temporary

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.