Searching for and manipulating the content of a keyword in a huge file
<p>I have a huge HTML file that I have converted to text file. (The file is Facebook home page's source). Assume the text file has a specific keyword in some places of it. For example: "some_keyword: [bla bla]". How would I print all the different bla blas that are followed by some_keyword?</p>

<pre><code>{id:"1126830890",name:"Hillary Clinton",firstName:"Hillary"}
</code></pre>

<p>Imagine there are 50 different names with this format in the page. How would I print all the names followed by "name:", considering the text is very large and crashes when you read() it or try to search through its lines. </p>

<p>Sample File: </p>

<p><code>shortProfiles:{"100000094503825":{id:"100000094503825",name:"Bla blah",firstName:"Blah",vanity:"blah",thumbSrc:"https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-1/c19.0.64.64/p64x64/10354686_10150004552801856_220367501106153455_n.jpg?oh=3b26bb13129d4f9a482d9c4115b9eeb2&amp;oe=5883062B",uri:"https://www.facebook.com/blah",gender:2,i18nGender:16777216,type:"friend",is_friend:true,mThumbSrcSmall:null,mThumbSrcLarge:null,dir:null,searchTokens:["Bla"],alternateName:"",is_nonfriend_messenger_contact:false},"1347968857":</code></p>

<p>Based on your comment, since you are the person responsible for writting the data to the file. Write the data in JSON format and read it from file using <a href="https://docs.python.org/2/library/json.html#json.loads" rel="nofollow"><code>json.loads()</code></a> as:</p>

<pre><code>import json
json_file = open('/path/to/your_file')
json_str = json_file.read()
json_data = json.loads(json_str)


for item in json_data:
    print item['name']
</code></pre>

<p><strong>Explanation:</strong></p>

<p>Lets say <code>data</code> is the variable storing </p>

<pre><code>{id:"1126830890",name:"Hillary Clinton",firstName:"Hillary"}
</code></pre>

<p>which will be dynamically changing within your code where you are performing write operation in the file. Instead append it to the list as:</p>

<pre><code>a = []
for item in page_content:
    # data = some xy logic on HTML file
    a.append(data)
</code></pre>

<p>Now write this list to the file using: <a href="https://docs.python.org/2/library/json.html#json.dump" rel="nofollow"><code>json.dump()</code></a> </p>

python