Remove <br> from element being extracted

247
July 19, 2017, at 03:45 AM

The website I am trying to extract data from is : http://www.genome.jp/dbget-bin/www_bget?ecs:ECs0037

and I am trying to extract the "nt sequence":

try:
    geneSeq = browser.find_element_by_xpath("html/body/div[1]/table/tbody/tr/td/table[2]/tbody/tr/td[1]/form/table/tbody/tr/td/table/tbody/tr[11]/td").text
except:
    geneSeq = "file\nnot found" 
geneSeq = geneSeq[geneSeq.find('\n')+1:]

I remove the first line of the input as I don't need it but I have br tags within the code which are registered in the file but python does not see them. I have tried .isspace() and it returns false and therefore .rsplit() does not work. Unfortunately the lines still show up when i try to write the sequence to file using f.write.

Is there a way to remove the br tag?

Answer 1

Assuming your html string is named html do this:

html = html.replace('<br>', '')

Answer 2

it will print whole html content in python:

import urllib2
req = urllib2.Request('https://www.google.com')
response = urllib2.urlopen(req)
the_page = response.read()
Answer 3

Thank you for all the answers, because python was not seeing the soace as whitespace i have just ended up doing a loop which checked for characters which seemed to work:

noSpace =""
for char in geneSeq:
    if char.isalpha():
        noSpace = noSpace + char
READ ALSO
PyCharm VCS annotations suddenly stopped working

PyCharm VCS annotations suddenly stopped working

Recently, I've encountered an unusual error with PyCharmUp until about a few days ago, the code editor would show my edit history as compared to the most recent Git version exactly as one might expect - the blue and green annotations showing what's changed

393
How to change the focus styling of a tkinter ttk.Treeview cell

How to change the focus styling of a tkinter ttk.Treeview cell

Even though my Treeview has the option takefocue=False, the text in the cells is still taking focus somehowSpecifically the text column when I do tree

362
How to connect unity with the server?

How to connect unity with the server?

Now I'm bulding game by UNITY3DI want to send json file to server to store it in database I build server by python in cherrypy Framework, i have problem with send data in client [UNITY3D] and retrieve it in server

411
how do I separate a text with a list?

how do I separate a text with a list?

this is my code however it keeps outputting the answer as one while I want it to count the characters in the sentence

241