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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:41:41+00:00 2026-06-08T10:41:41+00:00

Actually i am parsing some html pages by using scrapy, i have used xpath

  • 0

Actually i am parsing some html pages by using scrapy, i have used xpath and fetched some address from some html tag and the result is in the following form

result = ["Hno 4-50, Plot No 301, Swathi Pooja Homes,Beside Rajadhani Theater, Vikas Nagar,Dilsukhnagar,Hyderabad","Mr Sravan"]

And i want to join the string so i had done below

final_result = ','.join(result)

and got the following result

final_result = "Hno 4-50, Plot No 301, Swathi Pooja Homes,Beside Rajadhani Theater, Vikas Nagar,Dilsukhnagar,Hyderabad,Mr Sravan"

Here as we can observe that the name in the final_result (address) Mr Sravan is at the end, but generally the name should be before the door or house number in any contacts anywhere right?, so irrespective of number of strings in the list after joining it i should get the name at starting, is there any way to do this? can anyone please let me know how to do this?

Edited Code:

Presently i am parsing four urls at a time, so when i have used xpath(or related) and fetched address from different urls and the result(for example) is as below for each url

final_result = ['Addess_2','Newyork', 'Mr T.Jamal(Name)']
               ['Mr T. Jamal(Name)', 'Addres_1','Extra info'] 
               ['Addres_3','Mr T. Jamal(Name)','Extra info','Related scope'] 
               ['Addres_4','Extra info','Mr T. Jamal(Name)','Related info'] 
               ['Addres_5','Extra info','Related info']  # No name
               ['Addres_6','Extra info1','Related info1']  # No name

Here for all urls in parsing address want to write the code which works for all lists above

  • 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-08T10:41:43+00:00Added an answer on June 8, 2026 at 10:41 am

    How about something like this:

      final_result = result[-1] + ', ' + ''.join(result[:-1])
    

    yielding:

    Mr Sravan, Hno 4-50, Plot No 301, Swathi Pooja Homes,Beside Rajadhani Theater, Vikas Nagar,Dilsukhnagar,Hyderabad
    

    — UPDATE —

    This should find the “Mr” string anywhere in your original list and make it work the way you want.

    rs = ','.join(result).split(',')
    idx = [i for i,j in enumerate(rs) if j.strip().startswith('Mr')][0]
    final_result = (rs[idx] +',' + ','.join(rs[1:idx] + rs[idx+1:])).strip()
    print final_result
    

    This works with the 4 test strings provided in the update post by OP

    — UPDATE 2 OP changes question so that “Mr” may not be in list —

    This code will detect if Mr is in the list and move it to the front as above. It will also detect if it’s not in the list and avoid a index out of bounds condition. See output below.

    Test strings:

    result = ['Addres_4','Extra info','Mr T. Jamal(Name)','Related info'] 
    result = ['Addres_4','Extra info','T. Jamal(Name)','Related info'] 
    

    code:

    rs = ','.join(result).split(',')
    idx = [i for i,j in enumerate(rs) if j.strip().startswith('Mr')]
    
    if len(idx) == 1:  # we found "Mr" in the list
        idx = idx[0]
        final_result = (rs[idx] +',' + ','.join(rs[1:idx] + rs[idx+1:])).strip()
    else: # We didn't find "Mr" in the list .. adjust output to your needs
        final_result = (','.join(rs).strip())
    
    print final_result
    

    yield respectively:

    Mr T. Jamal(Name),Extra info,Related info
    Addres_4,Extra info,T. Jamal(Name),Related info
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some objects that I'm parsing from json using native browser implementations. Some
I am using HtmlAgility pack for parsing the html page. I am able to
I'm using domDocument to parse some HTML, and want to replace breaks with \n.
I'm currently using json-framework and need some help though parsing some JSON i'm getting
I have set up an HttpHandler for *css to do some simple parsing: <handlers>
I'm using Bison to create a simple parser and have some trouble understanding the
We have a small project that involves automatically parsing some server/mail logs (among other
I've been trying to do some simple DOM parsing of HTML documents and am
I want to preprocess files before gcc actually does its own preprocessing and parsing.
Actually I have to take the sequence number in $Revisions field.

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.