regex - Search html for text Python -


I am using urllib2 to get a webpage, and I have a specific value Need to seek. / P>

Is this the best way to do this by using a beautiful soup and using a search engine or using a regex to search the data?

Here is a very basic example of the text returned by the request:

  & lt; Html & gt; & Lt; Body & gt; & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; Div id = "123" class = "services" & gt; & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; Example BLL BLAP BLAB & lt; / Td> & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Div & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

In this case, I want to return "Example BLAP BLL BLL". The only thing that is consistently in it is "example" and I want to return all the data of this particular tag.

Using a beautiful, you can use it:

  & gt; & Gt; & Gt; Beautiful from the BS 4 import & gt; & Gt; & Gt; & Gt; & Gt; & Gt; Html_str = '' '... & lt; Html & gt; ... & lt; Body & gt; ... & lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; Example BLL BLAP BLAB & lt; / Td> ... & lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; ... & lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; ... & lt; Td style = "padding-left: 5px" bg color = "ffff" square = "style 8" & gt; BLLBLLLLL; Lt; / TD & gt; ... & lt; / Body & gt; ... & lt; / Html & gt; ... '' '& gt; & Gt; & Gt; Soup = Beautiful soup (html_str)> gt; & Gt; & Gt; For TD ('style 8') in SD: ... print (TD.Text) ... Examples: BLAP BLAP BLAP BLAP BLAP BLAP BLAP BLIP BLAP BLAP BLLAB  
< / Html>

Comments