I am quite new with Python...
I am writing a code that uses the urllib2
library to search through a certain web page. I am using the command re.findall
to search for specific strings on this web page. However, rather than extracting these specific strings, I want to extract THE ENTIRE LINE that these strings occur on.
For example, let's say I'm searching for the word "hello" on a web page that looks like this:
Hello, my name is Bob. I am Bob.
My friend is Jane.
My name is Jane... hello!
I want to extract the lines that contain "hello" in them. (So that means I would want to extract the first line and the third line.) This is what I've been using below, which is obviously wrong because it only extracts the word, not the entire line the word occurs on:
Page_Content = urllib2.urlopen(My_URL).read()
Matches = re.findall("hello", Page_Content)
How would I modify this code to extract the entire line? Would I have to use a for loop of some sort and search line by line? If so, how would I go about doing that?
for line in Page_Content
[code here]
?