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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:20:52+00:00 2026-06-11T12:20:52+00:00

sorry for the stupid question … just started using python (but I love it).

  • 0

sorry for the stupid question … just started using python (but I love it).

The problem:
I want to scrape data from the center for documentation of violism in syria. currently I’m using this scraper to collect the data. the problem is that I can access only one row instead of scraping all rows from the table.
the preferred output should look like

name status sex province area dateofdeath causeofdeath

import urllib2
from BeautifulSoup import BeautifulSoup
f = open('syriawar.tsv', 'w')
f.write("Row" + "\t" + "Data" + "\n")

for x in range (0,249):


syria = "file" + "\t" + str(x)
print "fetching data ... " + syria


url ='http://vdc-sy.org/index.php/en/martyrs/' + str(x) + '/c29ydGJ5PWEua2lsbGVkX2RhdGV8c29ydGRpcj1ERVNDfGFwcHJvdmVkPXZpc2libGV8c2hvdz0xfGV4dHJhZGlzcGxheT0wfA==' 

page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

sentence = soup.findAll('tr')[3].text

words = sentence
Data = str(words)

f.write(str(x) + "\t" + Data + "\n" )

f.close()
  • 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-11T12:20:53+00:00Added an answer on June 11, 2026 at 12:20 pm

    You need another layer of iteration. You should first call findAll(‘tr’) to get all the rows. Then remove the rows that are headers and empty and then loop through the remaining rows and call .text on those elements to get the text of the rows you want. Write each row to the file from within your inner loop.

    Here is the script fixed. Note that the utf-8 codec had to used because the page contains unicode in the text. You should verify that this is getting everything you want. The empty tags were causing Beautiful Soup some problems.

    import urllib2
    from bs4 import BeautifulSoup
    import codecs
    
    f = codecs.open('syriawar.tsv', 'w', 'utf-8')
    f.write("Row" + "\t" + "Data" + "\n")
    
    for x in range (0,249):
    
      syria = "file" + "\t" + str(x)
      print "fetching data ... " + syria
    
      url ='http://vdc-sy.org/index.php/en/martyrs/' + str(x) + '/c29ydGJ5PWEua2lsbGVkX2RhdGV8c29ydGRpcj1ERVNDfGFwcHJvdmVkPXZpc2libGV8c2hvdz0xfGV4dHJhZGlzcGxheT0wfA=='
    
      page = urllib2.urlopen(url)
      soup = BeautifulSoup(page)
    
      rows = soup.findAll('tr')
    
      i = 0;
      for row in rows[3:]:
         if i%2 == 0:
            f.write(str(i/2) + "\t" + row.text + "\n" )
         i += 1
    
    f.close()
    

    Another spiffy way to do this is to use Scrapemark. It works great for tables and lists.

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

Sidebar

Related Questions

Sorry for maybe this is stupid question, I just want download source code form
Sorry for asking a stupid question but I have a problem that makes me
First sorry if its a stupid question but i ran into a problem what
Sorry if this is a stupid question, but is there an easy way to
Really stupid question, sorry, but I can't find it on google (I'm sure it's
first sorry if its a stupid question but im lost a bit. So when
I'm sorry if it's a stupid question, but I don't now how to call
hello there and sorry for the stupid question but i think i might be
Sorry if this is a stupid question. I want to create an HTTP handler
Firstly I asked sorry if this is a stupid question. but I have a

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.