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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:07:58+00:00 2026-06-15T03:07:58+00:00

I have this code site = hxs.select(//h1[@class=’state’]) mydata = site.select(string()).extract() cleaned_mydata = re.sub(ur'(\s)\s+’, ur’\1′,

  • 0

I have this code

site = hxs.select("//h1[@class='state']")
mydata = site.select("string()").extract()
cleaned_mydata = re.sub(ur'(\s)\s+', ur'\1', mydata[0], flags=re.MULTILINE + re.UNICODE)

        log.msg(str(mydata),level=log.ERROR)
        log.msg(str(cleaned_mydata),level=log.ERROR)

The first output is

ERROR: [u’\r\n 212\r\n jobs containing php in xxxx
\r\n ‘]

other output is

jobs containing php in xxxxxx

regex is also stripping the 212 numeric with it. how can i fix that

  • 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-15T03:07:59+00:00Added an answer on June 15, 2026 at 3:07 am

    The problem is that this regex leaves the first whitespace it finds and strips only the subsequent ones.

    This means that

    u'\r\n 212\r\n jobs containing php in xxxx \r\n '
    

    becomes

    u'\r212\rjobs containing php in xxxx '
    

    When you print this, the 212 will be printed, then a carriage return will return the cursor to the first column, so that the following jobs... will overwrite the 212.

    This raises two questions:

    • You appear to be reading a text file in binary mode (otherwise the \r\n would have been normalized into \ns) – why?
    • Do you really want the regex to work this way?

    Edit:

    So, according to your comment, you want to

    • strip leading and trailing whitespace completely
    • condense multiple consecutive whitespace characters into a single space (ASCII 32).

    Then use

    cleaned_mydata = re.sub(r'\s+', ' ', mydata[0].strip())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code site = hxs.select(//h1[@class='state']) log.msg(str(site[0].extract()),level=log.ERROR) The ouput is [scrapy] ERROR: <h1
In one page of our site, I have this code: $_SESSION['returnURL'] = /store/checkout/onepage; and
I've used this code to have a like btn on my site: <iframe src=http://www.facebook.com/plugins/like.php?href=URL_OF_YOUR_WEBSITE&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80&amp
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
I have the following code snippet: using (SPSite site = new SPSite(this.ListAddress)) { using
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have this code: http://jsfiddle.net/AH4As/3/ It works in the fiddle, but on my site,
I have this code that is my navigation bar on my site, it is
I have this code to prepend www. to my site: RewriteCond %{HTTP_HOST} !^www\. RewriteCond
I have this code on javascript, var path = 'remote site action.php'; var form

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.