问:
Why can't I find method setContentLengthLong(long len) in HttpServletResponse?
I am in Eclipse and some time ago I was using this method: http://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setContentLengthLong(long) Now I can't manage to mek it work. I am using JDK 1.7 and I have inserted the following dependency in pom.xml:

```<code><dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>
</code>```

I have cleaned and updated the project with Maven. I have even closed and opened Eclipse. When I write:

```<code>response.setContentLengthLong(downloadFile.length());
</code>```

I get:

```<code>The method setContentLengthLong(long) is undefined for the type HttpServletResponse
</code>```

What am I doing wrong?

答:
I met the same problem today.
I am using IDEA, so I open the "Show Dependencies" from the maven tab, and search for the "servlet-api", there is one with version 2.4.

Exclude it from pom.xml, and build succeeded.

Body:
I am in Eclipse and some time ago I was using this method: http://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setContentLengthLong(long) Now I can't manage to mek it work. I am using JDK 1.7 and I have inserted the following dependency in pom.xml:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>

I have cleaned and updated the project with Maven. I have even closed and opened Eclipse. When I write:

response.setContentLengthLong(downloadFile.length());

I get:

The method setContentLengthLong(long) is undefined for the type HttpServletResponse

What am I doing wrong?


来源: stackexchange

问:
Jquery datatable Is showing no data in table on calling a web method from a simple web service
Im getting no data in table on calling a simple web service method. Im trying to put the data return by server side in a jquery datatable using datatble plugin. But its giving me no data in table with table headers. The webservice method is returning me Json data but also, a string tag is added so Im not sure if its entirely Json or not. May that might be the issue.I am fairly new to this and has always worked on server side part.In  my work, I deals with C# datatables a lot so I need to seralize datatable only and most of the time Im not even sure which columns the database is going to return So I cant go with any class file which represents the table structure. Is there any way to deal with that problem?? Any help is much appreciated.

```<code><script src="Scripts/jquery-3.1.1.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css" />
<script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            url: 'UserService.asmx/UserDetails',
            contentType: "application/json; charset=utf-8",
            method: 'post',
            datatype: 'json',
            success: function (data) {
                $('#tbl').dataTable({
                    data: data,
                    columns: [
                    { 'data': 'UserId' },
                    { 'data': 'UserName' },
                    { 'data': 'UserPassword' },
                    { 'data': 'RoleId' },
                    { 'data': 'Gender' },
                    { 'data': 'EmailId' },
                    { 'data': 'DateOfBirth' },
                    { 'data': 'Address' },
                    ]
                });
            },
            error: function() {
            alert('Fail!');
        }
        });
    });
</script>
</code>```

and my server side webservice code is

```<code>    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string UserDetails()
    {
        DataTable dt = new DataTable();
        dt.TableName = "UserDetails";
        SqlConnection conn;
        SqlCommand cmd;
        string connection = ConfigurationManager.ConnectionStrings["Connstr"].ToString();
        string command = "SELECT * FROM tbl_User";
        using (conn = new SqlConnection(connection))
        {
            cmd = new SqlCommand(command, conn);
            cmd.CommandType = CommandType.Text;
            conn.Open();
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(command, conn);
            da.Fill(dt);
            conn.Close();
        }
            var js = DataTableToJSONWithJavaScriptSerializer(dt);
        return js;
    }

    public string DataTableToJSONWithJavaScriptSerializer(DataTable dt)
        {
        JavaScriptSerializer js = new JavaScriptSerializer();
        List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>();
        Dictionary<string, object> childRow;
            foreach (DataRow row in dt.Rows)
            {
                childRow = new Dictionary<string, object>();
                foreach (DataColumn col in dt.Columns)
                {
                    childRow.Add(col.ColumnName, row[col]);
                }
                parentRow.Add(childRow);
            }
        return js.Serialize(parentRow);
        }
</code>```

The output of webservice method is in below format.

```<code>This XML file does not appear to have any style information associated with it. The document tree is shown below.
<string xmlns="http://tempuri.org/">
[{"UserId":"XYZ","UserName":"XYX","UserPassword":"XYX@1234","RoleId":1,"Gender":"F","EmailId":"XYX@email.com","DateOfBirth":"\/Date(623874600000)\/","Address":"ABC Str. 57"},
{"UserId":"ANATR","UserName":"ANT","UserPassword":"ABC@1234","RoleId":1,"Gender":"F","EmailId":"ANT@email.com","DateOfBirth":"\/Date(-301815000000)\/","Address":"XYZ. 2222"},
{"UserId":"WOLZA","UserName":"DIS","UserPassword":"AB@1234","RoleId":2,"Gender":"M","EmailId":"DIV@email.com","DateOfBirth":"\/Date(379362600000)\/","Address":"ul. JUMP 68"}]
</string>
</code>```

答:
try:

```<code>     success: function (data) {
         var d = JSON.parse(data.d);

            $('#tbl').dataTable({data:d,
</code>```

and so on.

ContentLicense: CC BY-SA 3.0

Body:
Im getting no data in table on calling a simple web service method. Im trying to put the data return by server side in a jquery datatable using datatble plugin. But its giving me no data in table with table headers. The webservice method is returning me Json data but also, a string tag is added so Im not sure if its entirely Json or not. May that might be the issue.I am fairly new to this and has always worked on server side part.In  my work, I deals with C# datatables a lot so I need to seralize datatable only and most of the time Im not even sure which columns the database is going to return So I cant go with any class file which represents the table structure. Is there any way to deal with that problem?? Any help is much appreciated.

<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css" />

and my server side webservice code is

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string UserDetails()
    {
        DataTable dt = new DataTable();
        dt.TableName = "UserDetails";
        SqlConnection conn;
        SqlCommand cmd;
        string connection = ConfigurationManager.ConnectionStrings["Connstr"].ToString();
        string command = "SELECT * FROM tbl_User";
        using (conn = new SqlConnection(connection))
        {
            cmd = new SqlCommand(command, conn);
            cmd.CommandType = CommandType.Text;
            conn.Open();
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(command, conn);
            da.Fill(dt);
            conn.Close();
        }
            var js = DataTableToJSONWithJavaScriptSerializer(dt);
        return js;
    }

    public string DataTableToJSONWithJavaScriptSerializer(DataTable dt)
        {
        JavaScriptSerializer js = new JavaScriptSerializer();
        List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>();
        Dictionary<string, object> childRow;
            foreach (DataRow row in dt.Rows)
            {
                childRow = new Dictionary<string, object>();
                foreach (DataColumn col in dt.Columns)
                {
                    childRow.Add(col.ColumnName, row[col]);
                }
                parentRow.Add(childRow);
            }
        return js.Serialize(parentRow);
        }

The output of webservice method is in below format.

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<string xmlns="http://tempuri.org/">
[{"UserId":"XYZ","UserName":"XYX","UserPassword":"XYX@1234","RoleId":1,"Gender":"F","EmailId":"XYX@email.com","DateOfBirth":"\/Date(623874600000)\/","Address":"ABC Str. 57"},
{"UserId":"ANATR","UserName":"ANT","UserPassword":"ABC@1234","RoleId":1,"Gender":"F","EmailId":"ANT@email.com","DateOfBirth":"\/Date(-301815000000)\/","Address":"XYZ. 2222"},
{"UserId":"WOLZA","UserName":"DIS","UserPassword":"AB@1234","RoleId":2,"Gender":"M","EmailId":"DIV@email.com","DateOfBirth":"\/Date(379362600000)\/","Address":"ul. JUMP 68"}]
</string>

Body:
try:

     success: function (data) {
         var d = JSON.parse(data.d);

            $('#tbl').dataTable({data:d,

and so on.


问:
How can I find the first occurrence in a string that is not numeric in java
I'm working on my own method in Java that will be able to calculate math equations given a string. Basically my calculator gets something like "698+33-47*2".
I want to split the parts (using substring and finding the characters '+', '-', '*', '/') but I'm not sure how to find the first non numeric character. My method is like this so far:</p>

```<code>public void DoEquation() {
  String s = storedData.getText() + data.getText();
  s = s.replaceAll(" ", "");

  ArrayList<String> list = new ArrayList<>();
  boolean checking = true;
  while (checking) {
    if (!s.contains("+") && !s.contains("-") && !s.contains("*") && !s.contains("/") {
      checking = false;
      break;
    }
    // Logic for extracting the numbers into the list
    // Then extract the mathamatical sign and place into list
  }
  System.out.println(list); // For testing
}
</code>```

答: You can use regx.  Or you can loop over each character in the string, extract a character by using charAt.  And then for each char, use Character.isDigit(char) to see if it is a digit.  You will need to think a little bit on how to handle the "-" character, which could be a negative (part of a digit) or it could be a minus sign.</p>

Body:
I'm working on my own method in Java that will be able to calculate math equations given a string. Basically my calculator gets something like "698+33-47*2".
I want to split the parts (using substring and finding the characters '+', '-', '*', '/') but I'm not sure how to find the first non numeric character. My method is like this so far:

public void DoEquation() {
  String s = storedData.getText() + data.getText();
  s = s.replaceAll(" ", "");

  ArrayList<String> list = new ArrayList<>();
  boolean checking = true;
  while (checking) {
    if (!s.contains("+") && !s.contains("-") && !s.contains("*") && !s.contains("/") {
      checking = false;
      break;
    }
    // Logic for extracting the numbers into the list
    // Then extract the mathamatical sign and place into list
  }
  System.out.println(list); // For testing
}


问:
How to change a label when a desired process is running
I'm trying to check if a process is running or not then display it within the application in a form of text. In this case If the process is not found, the application will display "Process not found" vs when its running, "Process is running"...

Example

Here's my current code:

```<code>    Dim p() As Process

    Private Sub CheckIfRunning()
        p = Process.GetProcessesByName("iw5sp")
        If p.Count > 0 Then
            ' Status: Game Not Found!
        Else
            ' Status: Game Found!
        End If
    End Sub
</code>```

答:
After endless searches, people being undermost unhelpful, and the 100% dis-votes, I finally present to you a solution! Works on VB.Net! Simple make a label, Insert this code. BOOM. All code was original other from ReadWritingMemory.vb.

```<code>Public Class Form1
Dim Timer1 As New Timer

    Public Function IsProcessRunning(Notepad As String) As Boolean
        For Each clsProcess As Process In Process.GetProcesses()
            If clsProcess.ProcessName.StartsWith(Notepad) Then
                Return True
            Else
            End If
        Next
        Return False
    End Function
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Run As Integer
        If Run = 0 Then
            AddHandler Timer1.Tick, AddressOf Timer1_Tick
            Timer1.Interval = 1
            Timer1.Start()

        Else
            RemoveHandler Timer1.Tick, AddressOf Timer1_Tick
            Timer1.Stop()
        End If
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs)
        Dim p() As Process
        p = Process.GetProcessesByName("notepad")
        If p.Count > 0 Then
            Label1.Text = "Status: Notepad Running!"
            Label1.Refresh()
        Else
            Label1.Text = "Status: Notepad Not Running!"
            Label1.Refresh()
        End If
    End Sub
End Class
</code>```

Be sure to have ReadWritingMemory.vb added to your class.
Code for that found here.

Visual Context:

Body:
I'm trying to check if a process is running or not then display it within the application in a form of text. In this case If the process is not found, the application will display "Process not found" vs when its running, "Process is running"...

Example

Here's my current code:

    Dim p() As Process

    Private Sub CheckIfRunning()
        p = Process.GetProcessesByName("iw5sp")
        If p.Count > 0 Then
            ' Status: Game Not Found!
        Else
            ' Status: Game Found!
        End If
    End Sub

Body:
After endless searches, people being undermost unhelpful, and the 100% dis-votes, I finally present to you a solution! Works on VB.Net! Simple make a label, Insert this code. BOOM. All code was original other from ReadWritingMemory.vb.

Public Class Form1
Dim Timer1 As New Timer

    Public Function IsProcessRunning(Notepad As String) As Boolean
        For Each clsProcess As Process In Process.GetProcesses()
            If clsProcess.ProcessName.StartsWith(Notepad) Then
                Return True
            Else
            End If
        Next
        Return False
    End Function
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Run As Integer
        If Run = 0 Then
            AddHandler Timer1.Tick, AddressOf Timer1_Tick
            Timer1.Interval = 1
            Timer1.Start()

        Else
            RemoveHandler Timer1.Tick, AddressOf Timer1_Tick
            Timer1.Stop()
        End If
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs)
        Dim p() As Process
        p = Process.GetProcessesByName("notepad")
        If p.Count > 0 Then
            Label1.Text = "Status: Notepad Running!"
            Label1.Refresh()
        Else
            Label1.Text = "Status: Notepad Not Running!"
            Label1.Refresh()
        End If
    End Sub
End Class

Be sure to have ReadWritingMemory.vb added to your class.
Code for that found here.

Visual Context:


问:
Windows Forms C# Program: How to check button status (enabled/disabled or visible/hidden)?
I have a program that, on error, will stop running. When it stops running, the "start" button is enabled and the "stop" button disables. While the program is running (after clicking "start"), the "start" button disables.

My goal is to write a program that, on interval (2 minutes), checks the status of the "start" button and sends an SMTP email when the "start" button becomes enabled. Thus letting me know when the program has stopped running.

I've been able to use FindWindow to find the program but I haven't been able to locate the button, let alone have my program differentiate enabled vs. disabled.

Using Spy++, the Handle of the button is 000A0B0A. The Style of the button when it is enabled is 54000000; disabled it is 5C000000. The program, or form/window, Handle is 00050B2C.

My question is: What command, if any, can I use to check the Style of that particular button (Handle 00A0B0A)?

答:
It sounds like what you are generally need is to add observability to your program so you can monitor its state (running, stopped, error, etc.).

I would suggest a different (and possibly simpler approach) that doesn't rely on the UI which could change in the future and which may be more extendable in the case that you would like to observe different information on your application in the future.

Why don't you instead fire status events from your program on error? There are several different ways to do this from the product (wcf, remoting, writing to the event viewer, etc.) and have your external application register for these events and act accordingly (e.g. send an email)?

It may be a little extra work in the beginning (though I'm not sure since you are already running into issues with your approach, and writing a simple wcf service that fires events doesn't take that much time) but I think well worth it in the future.

ContentLicense: CC BY-SA 2.5


问:
HashMap have old value around till they stop being referenced
I have a situation where I load some data at application level inside a HashMapin my android application. I use one of the entries (with a particular keyA in the HashMap) in this map to initialise some data inside my Activity and this Activity hangs around for a while. While the user is on this activity, the HashMap from which I referenced the object for keyA might change. The code to update the HashMap is written by me. When I want to update the HashMap, I want to clear the entire HashMap(so that its size() returns 0) and want to populate everything again. If I call HashMap.clear(), would it make the old objects to be garbage collected?

If yes, what is the best way to clear the entire HashMap so that I don't loose the old objects if they are being referred to anywhere else in the code. What would be the best to reassign values to the HashMap in this case?

PS: I am using ReentrantReadWriteLock for maintaining the access if that might help.

答:
If I call HashMap.clear(), would it make the old objects to be garbage collected?

A HashMap is just storing a single reference to an object.  When you call clear(), then the object can be gc'd if (and only if) the only reference to the object was the HashMap.  If other parts of the code have references to the object then it won't be.  That's how gc works.  HashMap isn't magic.

What would be the best to reassign values to the HashMap in this case?

If you are updating the values in a shared map then your code is going to have to re-get the values from the map whenever they use them – or maybe every so often.  I'd first re-get the value each time you use it and then prove to yourself that it's too expensive before doing anything else.

PS: I am using ReentrantReadWriteLock for maintaining the access if that might help.

I'd switch to using a ConcurrentHashMap and not both with the expense and code maintenance of doing the locking yourself.


问:
InfluxDB DataFrameClient KeyError: 83
I am building a somewhat automated query builder for a process I have that needs to query data from influx for a time range. Towards that end, I need to filter by time, which means I need epoch millisecond strings in my query. This code throws the following error.

```<code>import pandas as pd

ts = pd.Timestamp(pd.Timestamp('now', tz='US/Pacific').date(), tz='US/Pacific')
ts_str = str(int(ts.value / (10 ** 6)))
query_str = 'SELECT * FROM "table"."measurement" WHERE time <= ' + \
            ts_str + 'ms LIMIT 10'
json_payload = client.query(query_str)
print(json_payload)
</code>```

and the stack trace:

```<code>Traceback (most recent call last):
  File "my_code.py", line 31, in query
    return self.client.query(query)
  File "/usr/local/lib/python2.7/site-packages/influxdb/_dataframe_client.py", line 138, in query
    results = super(DataFrameClient, self).query(query, database=database)
  File "/usr/local/lib/python2.7/site-packages/influxdb/client.py", line 339, in query
    expected_response_code=expected_response_code
  File "/usr/local/lib/python2.7/site-packages/influxdb/client.py", line 239, in request
    timeout=self._timeout
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 407, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 302, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 426, in prepare_url
    enc_params = self._encode_params(params)
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 104, in _encode_params
    return urlencode(result, doseq=True)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1353, in urlencode
    v = quote_plus(v)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1308, in quote_plus
    s = quote(s, safe + ' ')
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1303, in quote
    return ''.join(map(quoter, s))
KeyError: 83
</code>```

答:
Influx is very picky about unicode, single quotes, double quotes, etc. Swapping out str for unicode for ts_str works. Printing out the query_str before and after looks the same, but under the hood the type matters. </p>

```<code>import pandas as pd

ts = pd.Timestamp(pd.Timestamp('now', tz='US/Pacific').date(), tz='US/Pacific')
ts_str = unicode(int(ts.value / (10 ** 6)))
query_str = 'SELECT * FROM "table"."measurement" WHERE time <= ' + \
            ts_str + 'ms LIMIT 10'
json_payload = client.query(query_str)
print(json_payload)
</code>```

Title: InfluxDB DataFrameClient KeyError: 83

Body:
I am building a somewhat automated query builder for a process I have that needs to query data from influx for a time range. Towards that end, I need to filter by time, which means I need epoch millisecond strings in my query. This code throws the following error.

import pandas as pd

ts = pd.Timestamp(pd.Timestamp('now', tz='US/Pacific').date(), tz='US/Pacific')
ts_str = str(int(ts.value / (10 ** 6)))
query_str = 'SELECT * FROM "table"."measurement" WHERE time <= ' + \
            ts_str + 'ms LIMIT 10'
json_payload = client.query(query_str)
print(json_payload)

and the stack trace:

Traceback (most recent call last):
  File "my_code.py", line 31, in query
    return self.client.query(query)
  File "/usr/local/lib/python2.7/site-packages/influxdb/_dataframe_client.py", line 138, in query
    results = super(DataFrameClient, self).query(query, database=database)
  File "/usr/local/lib/python2.7/site-packages/influxdb/client.py", line 339, in query
    expected_response_code=expected_response_code
  File "/usr/local/lib/python2.7/site-packages/influxdb/client.py", line 239, in request
    timeout=self._timeout
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 407, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 302, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 426, in prepare_url
    enc_params = self._encode_params(params)
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 104, in _encode_params
    return urlencode(result, doseq=True)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1353, in urlencode
    v = quote_plus(v)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1308, in quote_plus
    s = quote(s, safe + ' ')
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1303, in quote
    return ''.join(map(quoter, s))
KeyError: 83

Body:
Influx is very picky about unicode, single quotes, double quotes, etc. Swapping out str for unicode for ts_str works. Printing out the query_str before and after looks the same, but under the hood the type matters.

import pandas as pd

ts = pd.Timestamp(pd.Timestamp('now', tz='US/Pacific').date(), tz='US/Pacific')
ts_str = unicode(int(ts.value / (10 ** 6)))
query_str = 'SELECT * FROM "table"."measurement" WHERE time <= ' + \
            ts_str + 'ms LIMIT 10'
json_payload = client.query(query_str)
print(json_payload)


问:
python3.5 PIL Image not displaying image
The following code does not display the image lists.jpg (in current dir):

print(dir(Image)) displays components; im.size, im.filename, im.format all return correct values.

What have I not done to display this jpg file?

```<code>from PIL import Image
im = Image.open("lists.jpg")
im.show()  # did not work -  perhaps due to the environment Jupyter Notebooks
</code>```

Solution: replaced module with another with immediate results.

```<code>from IPython.display import Image
Image(filename='lists.jpg')
</code>```

答:
To display the image on screen:

```<code>from PIL import Image
im = Image.open("lists.jpg")
im.show()
</code>```

See also http://pillow.readthedocs.io/en/4.0.x/reference/Image.html

Body:
The following code does not display the image lists.jpg (in current dir):

print(dir(Image)) displays components; im.size, im.filename, im.format all return correct values.

What have I not done to display this jpg file?

from PIL import Image
im = Image.open("lists.jpg")
im.show()  # did not work -  perhaps due to the environment Jupyter Notebooks

Solution: replaced module with another with immediate results.

from IPython.display import Image
Image(filename='lists.jpg')

Body:
To display the image on screen:

from PIL import Image
im = Image.open("lists.jpg")
im.show()

See also http://pillow.readthedocs.io/en/4.0.x/reference/Image.html


问:
How to create a library
I have some code which I want to organize into a class or library for other developers to use more easily on their website.

The way I use the class now is to instantiate an instance of it and start calling the functions I need as I need them.

```<code>$class_object = new MyClass();
$class_object->myFunction();
</code>```

Is this basically all I need to make a library, or do I need to make further changes to turn this into a library?

答:
It depends a lot on the functionality that you're providing. If the library is just a group of functions, then it might be best to have them static:

```<code>class MyLib
{
    public static function convertData( $data )
    {
        // Do something
    }
}
</code>```

But if it depends on the object being instantiated and stored information within that object, then I'd leave it as-is. It all depends on how you use it.

Title: How to create a library

Body:
I have some code which I want to organize into a class or library for other developers to use more easily on their website.

The way I use the class now is to instantiate an instance of it and start calling the functions I need as I need them.

$class_object = new MyClass();
$class_object->myFunction();

Is this basically all I need to make a library, or do I need to make further changes to turn this into a library?

Body:
It depends a lot on the functionality that you're providing. If the library is just a group of functions, then it might be best to have them static:

class MyLib
{
    public static function convertData( $data )
    {
        // Do something
    }
}

But if it depends on the object being instantiated and stored information within that object, then I'd leave it as-is. It all depends on how you use it.


问:
How to get content from another page in uwp after a few seconds
I have Page1.xaml

```<code><Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="575">

        <TextBlock Foreground="White" TextWrapping="Wrap" Margin="28,20,31,0" FontSize="14" Height="145">
            <TextBlock.Transitions>
                <TransitionCollection>
                    <EntranceThemeTransition FromHorizontalOffset="400"/>
                </TransitionCollection>
            </TextBlock.Transitions>
            <Run Text="Text 1"/>
        </TextBlock>
    </StackPanel>
</Grid>
</code>```

And Page2.xaml

```<code> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Foreground="White SelectionChanged="TextBlock_SelectionChanged"
Name="TextBlockOne">
        <TextBlock.Transitions>
            <TransitionCollection>
                <EntranceThemeTransition FromHorizontalOffset="400"/>
            </TransitionCollection>
        </TextBlock.Transitions>
        <Run Text="Text 2"/>
    </TextBlock>
</Grid>
</code>```

What I want to do is to replace "Text 1" in page 1 after 5 seconds with "Text 2" from Page 2.

I tried this in Page2.xaml.cs:

```<code>private void TextBlock_SelectionChanged(object sender, RoutedEventArgs e)
    {
        var test = TextBlockOne.Text;
        Frame.Navigate(typeof(Page1), test);
    }
</code>```

How do I solve this problem?

答:
You can use MainPage to Navigate it.

First, the MainPage have a Frame that can navigate to Apage .

Then,MainPage start a Timer that can wait 5 second for call the MainPage to Navigate to Bpage.

The code in xaml ,I write in MainPage

```<code><Frame x:Name="frame"/>
</code>```

The code in xaml.cs

```<code>    public MainPage()
    {
        this.InitializeComponent();
        frame.Navigate(typeof(APage));
        DispatcherTimer t = new DispatcherTimer();
        t.Interval = new TimeSpan(1000);
        t.Tick += (s, e) =>
        {
            NavigatePageB();
        };
        t.Start();
    }

    private async void NavigatePageB()
    {
        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
         () =>
         {
             frame.Navigate(typeof(PageB));
         });
    }
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have Page1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="575">

        <TextBlock Foreground="White" TextWrapping="Wrap" Margin="28,20,31,0" FontSize="14" Height="145">
            <TextBlock.Transitions>
                <TransitionCollection>
                    <EntranceThemeTransition FromHorizontalOffset="400"/>
                </TransitionCollection>
            </TextBlock.Transitions>
            <Run Text="Text 1"/>
        </TextBlock>
    </StackPanel>
</Grid>

And Page2.xaml

 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Foreground="White SelectionChanged="TextBlock_SelectionChanged"
Name="TextBlockOne">
        <TextBlock.Transitions>
            <TransitionCollection>
                <EntranceThemeTransition FromHorizontalOffset="400"/>
            </TransitionCollection>
        </TextBlock.Transitions>
        <Run Text="Text 2"/>
    </TextBlock>
</Grid>

What I want to do is to replace "Text 1" in page 1 after 5 seconds with "Text 2" from Page 2.

I tried this in Page2.xaml.cs:

private void TextBlock_SelectionChanged(object sender, RoutedEventArgs e)
    {
        var test = TextBlockOne.Text;
        Frame.Navigate(typeof(Page1), test);
    }

How do I solve this problem?

Body:
You can use MainPage to Navigate it.

First, the MainPage have a Frame that can navigate to Apage .

Then,MainPage start a Timer that can wait 5 second for call the MainPage to Navigate to Bpage.

The code in xaml ,I write in MainPage

<Frame x:Name="frame"/>

The code in xaml.cs

    public MainPage()
    {
        this.InitializeComponent();
        frame.Navigate(typeof(APage));
        DispatcherTimer t = new DispatcherTimer();
        t.Interval = new TimeSpan(1000);
        t.Tick += (s, e) =>
        {
            NavigatePageB();
        };
        t.Start();
    }

    private async void NavigatePageB()
    {
        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
         () =>
         {
             frame.Navigate(typeof(PageB));
         });
    }


问:
Get coordinate of google map_click event Ionic
Im trying to read the coordinates of a google map_click event.
I've tried:

```<code>map.on(GoogleMapsEvent.MAP_CLICK).subscribe((e) => {
 console.log(e.LatLng.lat());
})
</code>```

which doesnt work.

I imported googlemap via ionic-native.

答:
EDIT

so i found out its just e.lat

Body:
Im trying to read the coordinates of a google map_click event.
I've tried:

map.on(GoogleMapsEvent.MAP_CLICK).subscribe((e) => {
 console.log(e.LatLng.lat());
})

which doesnt work.

I imported googlemap via ionic-native.

Body:
EDIT

so i found out its just e.lat


问:
X Path Python Error- 'list' object has no attribute 'xpath'
I am trying to do a Web-Crawling project, and I am keep on getting an error code called "'list' object has no attribute 'xpath'"/

This is the code so far:

```<code>import requests
from lxml import html
import pandas

url = "http://www.cnbc.com/"
response = requests.get(url)
doc = html.fromstring(response.text)

headlineNode = doc.xpath('//div[@class="headline"]')
len(headlineNode)

headlines = headlineNode.xpath('/a')
len(headlines)
</code>```

I want to extraxt the headlines from CNBC Home, but I am keep on getting an error saying

```<code>---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-d9f54582133c> in <module>()
----> 1 headlines = headlineNode.xpath('/a')
      2 len(headlines)

AttributeError: 'list' object has no attribute 'xpath'
</code>```

Is there anyway to fix this?

答:
The reason you are getting this error is because xpath always results a list of elements and xpath can be called on elements.

So to get expected results, what you can do is iterate over the headlineNode list and then call the xpath to the element nodes such as node.xpath('/a')

The following code will give you the list of all the url you needed as a list. You can do something like this :

```<code>import requests
from lxml import html
import pandas

url = "http://www.cnbc.com/"
response = requests.get(url)
doc = html.fromstring(response.text)

headlineNode = doc.xpath('//div[@class="headline"]')
len(headlineNode)

url_list  = []
for node in headlineNode :
    url_node = node.xpath('./a/@href')
    if url_node :
        url_list.append(url + url_node[0].strip())
print(url_list)
len(url_list)
</code>```

This will result in :

```<code>['http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'http://www.cnbc.com/2017/03/28/us-markets.html', 'http://www.cnbc.com/2017/03/28/european-markets-investors-shrug-off-trump-concerns.html', 'http://www.cnbc.com/2017/03/27/gold-steady-as-dollar-edges-up-focus-on-trump-agenda.html', 'http://www.cnbc.com/2017/03/27/weaker-dollar-lifts-oil-futures-but-soaring-us-output-weighs.html', 'http://www.cnbc.com/2017/03/28/us-treasurys-edge-lower-as-investors-eye-data-auctions.html', 'http://www.cnbc.com/2017/03/27/dollar-limps-away-from-multi-month-lows-still-seen-vulnerable.html', 'http://www.cnbc.com/2017/03/27/dollar-limps-away-from-multi-month-lows-still-seen-vulnerable.html', 'http://www.cnbc.com/2017/03/28/markets-could-see-heartbreak-if-brexit-is-hard-to-do.html', 'http://www.cnbc.com/2017/03/28/former-google-exec-heres-how-to-know-its-time-to-fire-an-employee.html', 'http://www.cnbc.com/2017/03/28/chinas-secret-plan-to-crush-spacex-and-the-us-space-program.html', 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'http://www.cnbc.com/2017/03/28/following-tuesdays-rally-stocks-will-grind-higher-into-2018-analyst-says.html', 'http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'http://www.cnbc.com/2017/03/28/made-in-america-impossible-tech-startups.html', 'http://www.cnbc.com/2017/03/28/toshibas-westinghouse-to-file-for-us-bankruptcy-sources.html', 'http://www.cnbc.com/2017/03/28/early-reports-of-damage-in-wake-of-australias-cyclone-debbie.html', 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'http://www.cnbc.com/2017/03/28/rodrigo-duterte-turns-72-a-look-at-his-controversial-presidency-so-far-commentary.html', 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'http://www.cnbc.com/2017/03/28/congress-clears-way-for-isps-to-sell-browsing-history.html', 'http://www.cnbc.com/2017/03/28/british-pm-may-to-fire-starting-gun-on-brexit.html', 'http://www.cnbc.com/2017/03/28/brexit-is-like-arthritis-it-doesnt-kill-you-but-it-hits-you-says-former-boe-member.html', 'http://www.cnbc.com/2017/03/27/florida-preparesfor-xi-jinpingsvisit.html', 'http://www.cnbc.com/2017/03/28/us-heading-for-recession-after-2-years-of-unsustainable-growth-economist-says.html', 'http://www.cnbc.com/2017/03/28/this-is-what-immigration-means-to-the-us-economy-in-two-charts.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'http://www.cnbc.com/2017/03/28/next-iphone-is-last-hurrah-for-smartphones-apple.html', 'http://www.cnbc.com/2017/03/28/south-africa-speculates-over-possible-firing-of-finance-minister.html', 'http://www.cnbc.com/2017/03/28/snap-was-a-drunk-at-the-wheel-but-now-looks-like-a-very-real-business-fund-manager-says.html', 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'http://www.cnbc.com/2017/03/28/siemens-medical-solutions-wins-41-billion-us-defense-contract.html', 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'http://www.cnbc.com/2017/03/28/trump-to-meet-egyptian-president-at-white-house-on-april-3.html', 'http://www.cnbc.com/2017/03/28/tesla-is-rejecting-a-racial-harassment-lawsuit-filed-by-an-assembly-line-worker.html', 'http://www.cnbc.com/2017/03/28/jpmorgan-says-markets-are-underestimating-the-upside-of-asian-banks.html', 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'http://www.cnbc.com/https://www.facebook.com/cnbcinternational/', 'http://www.cnbc.com/https://twitter.com/cnbcworld', 'http://www.cnbc.com/http://www.linkedin.com/company/2966126', 'http://www.cnbc.com/http://www.youtube.com/user/CNBCInternational', 'http://www.cnbc.com/http://www.cnbc.com/id/28295763', 'http://www.cnbc.com/pre-markets/', 'http://www.cnbc.com/http://www.cnbc.com/world-markets-heat-map/', 'http://www.cnbc.com/dow-components/', 'http://www.cnbc.com/http://data.cnbc.com/quotes/aapl%2Caxp%2Cba%2Ccat%2Ccsco%2Ccvx%2Cdd%2Cdis%2Cge%2Cgs%2Chd%2Cibm%2Cintc%2Cjnj%2Cjpm%2Cko%2Cmcd%2Cmmm%2Cmrk%2Cmsft%2Cnke%2Cpfe%2Cpg%2Ctrv%2Cunh%2Cutx%2Cv%2Cvz%2Cwmt%2Cxom', 'http://www.cnbc.com/sectors/', 'http://www.cnbc.com/2017/03/27/dollar-limps-away-from-multi-month-lows-still-seen-vulnerable.html', 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'http://www.cnbc.com/2017/03/28/iran-says-russia-can-use-its-military-bases-on-case-by-case-basis.html', 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'http://www.cnbc.com/2017/03/28/hootsuite-ceo-talks-social-media-and-trump.html', 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'http://www.cnbc.com/2017/03/28/dow-trump-dollar-kushner-stoxx-wallstreet.html', 'http://www.cnbc.com/2017/03/27/trump-brexit-healthcare-russia-dow-stoxx.html', 'http://www.cnbc.com/2017/03/24/trump-healthcare-markets-us-dow-stocks.html', 'http://www.cnbc.com/2017/03/23/trump-london-terrorism-markets-stocks-dow-ftse-may-uk-us.html', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000603723', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000602217', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000600643', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000598102', 'http://www.cnbc.com/2017/03/26/trader-poll-which-will-garner-the-most-market-attention.html', 'http://www.cnbc.com/2017/03/20/trader-poll-what-are-chinas-greatest-challenges.html', 'http://www.cnbc.com/2017/03/12/trader-poll-is-the-fed-definitely-going-to-hike-rates-at-this-meeting.html', 'http://www.cnbc.com/2017/03/06/trader-poll-has-the-us-dollar-got-higher-to-go.html', 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'http://www.cnbc.com/advertorial/2017/03/09/breathing-new-life-into-brands.html', 'http://www.cnbc.com/2017/03/23/make-sure-youre-not-replaced-by-a-machine-microsoft-us-chief-marketer.html', 'http://www.cnbc.com/2017/03/23/online-ads-need-to-stop-being-intrusive-eurosport.html', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595689', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595687', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595688', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595690', 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'http://www.cnbc.com/2017/03/23/engineers-develop-solar-powered-skin-which-could-transform-lives.html', 'http://www.cnbc.com/2017/03/23/palm-oil-its-uses-and-ways-to-limit-its-impact.html', 'http://www.cnbc.com/advertorial/2017/03/13/access-to-energy-when-business-issues-meet-social-impacts.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'http://www.cnbc.com/2017/03/28/amazon-to-acquire-souqcom-a-large-e-commerce-site-in-the-middle-east.html', 'http://www.cnbc.com/advertorial/2016/12/13/a-new-era-of-intelligent-machinery.html', 'http://www.cnbc.com/advertorial/2016/12/05/the-reimagining-of-cities.html', 'http://www.cnbc.com/advertorial/2016/11/22/could-mining-asteroids-save-earth.html', 'http://www.cnbc.com/advertorial/2016/11/02/smarter-ships-safer-seas.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'http://www.cnbc.com/2017/03/28/risk-of-correction-quite-high-but-wont-kill-bull-market-says-goldman-sachs-strategist.html', 'http://www.cnbc.com/2017/03/28/samsung-galaxy-s8-apple-iphone-8-launch.html', 'http://www.cnbc.com/2017/03/28/made-in-america-impossible-tech-startups.html', 'http://www.cnbc.com/2017/03/28/facebook-stole-these-features-from-snapchat.html', 'http://www.cnbc.com/2017/03/28/cisco-separating-some-key-networking-software-from-hardware--report.html', 'http://www.cnbc.com/2017/03/28/uber-releases-diversity-report-and-repudiates-its-hard-charging-attitude.html', 'http://www.cnbc.com/2017/03/28/cramers-charts-explain-why-general-mills-looks-ripe-for-a-run.html', 'http://www.cnbc.com/2017/03/28/cramer-why-it-might-be-time-for-you-to-unfollow-trumps-twitter-feed.html', 'http://www.cnbc.com/2017/03/28/blackrock-plans-major-changes-to-its-active-stockpicking-business.html', 'http://www.cnbc.com/2017/03/28/darden-shares-pop-4-percent-on-strong-earnings-beat-cheddars-acquisition.html', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605169', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605171', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605046', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605164', 'http://www.cnbc.com/2017/03/28/nunes-seems-like-the-wrong-person-to-lead-trump-russia-probe-commentary.html', 'http://www.cnbc.com/2017/03/28/donald-trump-is-making-his-russia-scandal-about-clintons-commentary.html', 'http://www.cnbc.com/2017/03/28/self-made-millionaire-shares-3-tricks-for-raising-successful-kids.html', 'http://www.cnbc.com/2017/03/28/president-trump-is-directing-his-anger-at-the-wrong-people-commentary.html']
</code>```

To add title also to the result_list, you can modify it something like this :

```<code>import requests
from lxml import html
import pandas

url = "http://www.cnbc.com/"
response = requests.get(url)
doc = html.fromstring(response.text)

headlineNode = doc.xpath('//div[@class="headline"]')
len(headlineNode)

result_list  = []
for node in headlineNode :
    url_node = node.xpath('./a/@href')
    title = node.xpath('./a/text()')
    if (url_node and title) :
        result_list.append({'url' : url + url_node[0].strip(),
            'title' : title[0].strip()})
print(result_list)
len(result_list)
</code>```

This will result in :

```<code>[{'url': 'http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'title': 'Asia up higher after Dow breaks 8-day losing streak, Brexit ahead'}, {'url': 'http://www.cnbc.com/2017/03/28/us-markets.html', 'title': 'Dow snaps 8-day losing streak as consumer confidence surges; financials lead'}, {'url': 'http://www.cnbc.com/2017/03/28/european-markets-investors-shrug-off-trump-concerns.html', 'title': 'European stocks close higher as investors shrug off Trump concerns; Wolseley up 5%'}, {'url': 'http://www.cnbc.com/2017/03/27/gold-steady-as-dollar-edges-up-focus-on-trump-agenda.html', 'title': 'Gold rises as investors focus on Trump agenda'}, {'url': 'http://www.cnbc.com/2017/03/27/weaker-dollar-lifts-oil-futures-but-soaring-us-output-weighs.html', 'title': 'US crude settles at $48.37, rising 64 cents with Libyan output disruption'}, {'url': 'http://www.cnbc.com/2017/03/28/us-treasurys-edge-lower-as-investors-eye-data-auctions.html', 'title': 'US Treasurys mostly higher as investors digest data, 5-year note auction'}, {'url': 'http://www.cnbc.com/2017/03/28/dollar-bounces-on-fed-talk-sterling-wobbles-on-brexit-anxiety.html', 'title': 'Dollar bounces on Fed talk, sterling wobbles on Brexit anxiety'}, {'url': 'http://www.cnbc.com/2017/03/28/dollar-bounces-on-fed-talk-sterling-wobbles-on-brexit-anxiety.html', 'title': 'Dollar bounces on Fed talk, sterling wobbles on Brexit anxiety'}, {'url': 'http://www.cnbc.com/2017/03/28/markets-could-see-heartbreak-if-brexit-is-hard-to-do.html', 'title': 'Markets could see heartbreak if Brexit is hard to do'}, {'url': 'http://www.cnbc.com/2017/03/28/former-google-exec-heres-how-to-know-its-time-to-fire-an-employee.html', 'title': "Former Google exec: Here's how to know it's time to fire an employee"}, {'url': 'http://www.cnbc.com/2017/03/28/chinas-secret-plan-to-crush-spacex-and-the-us-space-program.html', 'title': "China's secret plan to crush SpaceX and the US space program"}, {'url': 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'title': "Le Pen victory could be five times as dangerous as Greece's financial meltdown: UBS"}, {'url': 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'title': 'How this tiny country went from nuclear problem child to role model'}, {'url': 'http://www.cnbc.com/2017/03/28/following-tuesdays-rally-stocks-will-grind-higher-into-2018-analyst-says.html', 'title': "Following Tuesday's rally, stocks will 'grind higher' into 2018, analyst says"}, {'url': 'http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'title': 'Asia up higher after Dow breaks 8-day losing streak, Brexit ahead'}, {'url': 'http://www.cnbc.com/2017/03/28/made-in-america-impossible-tech-startups.html', 'title': "These three start-ups show why it's so hard to build products in America"}, {'url': 'http://www.cnbc.com/2017/03/28/japans-tepid-retail-sales-raise-concerns-about-consumption-growth.html', 'title': "Japan's tepid retail sales raise concerns about consumption, growth"}, {'url': 'http://www.cnbc.com/2017/03/28/toshibas-westinghouse-to-file-for-us-bankruptcy-sources.html', 'title': "Toshiba's Westinghouse to file for US bankruptcy: Sources"}, {'url': 'http://www.cnbc.com/2017/03/28/early-reports-of-damage-in-wake-of-australias-cyclone-debbie.html', 'title': "Early reports of damage in wake of Australia's Cyclone Debbie"}, {'url': 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'title': 'Tesla deal boosts Chinese presence in US auto tech'}, {'url': 'http://www.cnbc.com/2017/03/28/rodrigo-duterte-turns-72-a-look-at-his-controversial-presidency-so-far-commentary.html', 'title': 'As Rodrigo Duterte turns 72, a look at his controversial presidency so far'}, {'url': 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'title': 'North Korea could be in final stages of nuclear test preparations: Report'}, {'url': 'http://www.cnbc.com/2017/03/28/congress-clears-way-for-isps-to-sell-browsing-history.html', 'title': 'Congress just cleared the way for internet providers to sell your web browsing history'}, {'url': 'http://www.cnbc.com/2017/03/28/british-pm-may-to-fire-starting-gun-on-brexit.html', 'title': 'British PM May to fire starting gun on Brexit'}, {'url': 'http://www.cnbc.com/2017/03/28/brexit-is-like-arthritis-it-doesnt-kill-you-but-it-hits-you-says-former-boe-member.html', 'title': u'Brexit is like arthritis, it doesn\u2019t kill you but it hits you, says former BOE member'}, {'url': 'http://www.cnbc.com/2017/03/27/florida-preparesfor-xi-jinpingsvisit.html', 'title': u"Florida authorities prep\xa0for Xi Jinping's\xa0visit"}, {'url': 'http://www.cnbc.com/2017/03/28/us-heading-for-recession-after-2-years-of-unsustainable-growth-economist-says.html', 'title': 'US heading for recession after 2 years of unsustainable growth, economist says'}, {'url': 'http://www.cnbc.com/2017/03/28/this-is-what-immigration-means-to-the-us-economy-in-two-charts.html', 'title': 'This is what immigration means to the U.S. economy in two charts'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'title': u'Jack Dorsey brushes off calls to quit as CEO, says will do \u2018whatever it takes\u2019 for Twitter, Square to succeed'}, {'url': 'http://www.cnbc.com/2017/03/28/next-iphone-is-last-hurrah-for-smartphones-apple.html', 'title': 'The next iPhone is the last hurrah for smartphones: Fund manager'}, {'url': 'http://www.cnbc.com/2017/03/28/south-africa-speculates-over-possible-firing-of-finance-minister.html', 'title': 'South Africa faces uncertain wait amid speculation finance minister is to be fired'}, {'url': 'http://www.cnbc.com/2017/03/28/snap-was-a-drunk-at-the-wheel-but-now-looks-like-a-very-real-business-fund-manager-says.html', 'title': "Snap was a 'drunk at the wheel' but now looks like a very real business, fund manager says"}, {'url': 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'title': 'This ad agency is standing against xenophobia and rebranding with the name of its Jewish founders'}, {'url': 'http://www.cnbc.com/2017/03/28/siemens-medical-solutions-wins-41-billion-us-defense-contract.html', 'title': 'Siemens Medical Solutions wins $4.1 billion US defense contract'}, {'url': 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'title': 'Google Home A.I. speaker is coming to the UK to challenge Amazon Echo'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'title': u'Is the US government ready for the impact of AI? \u2018I don\u2019t know,\u2019 Twitter CEO Jack Dorsey says'}, {'url': 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'title': u'UK introduces super secure new \xa31 coin'}, {'url': 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'title': "'Major' solar project gets the green light in Northern Ireland"}, {'url': 'http://www.cnbc.com/2017/03/28/trump-to-meet-egyptian-president-at-white-house-on-april-3.html', 'title': 'Trump to meet Egyptian president at White House on April 3'}, {'url': 'http://www.cnbc.com/2017/03/28/tesla-is-rejecting-a-racial-harassment-lawsuit-filed-by-an-assembly-line-worker.html', 'title': 'Tesla rejects racial harassment lawsuit filed by assembly line worker'}, {'url': 'http://www.cnbc.com/2017/03/28/jpmorgan-says-markets-are-underestimating-the-upside-of-asian-banks.html', 'title': 'JPMorgan says markets are underestimating the upside of Asian banks'}, {'url': 'http://www.cnbc.com/https://www.facebook.com/cnbcinternational/', 'title': 'Facebook'}, {'url': 'http://www.cnbc.com/https://twitter.com/cnbcworld', 'title': 'Twitter'}, {'url': 'http://www.cnbc.com/http://www.linkedin.com/company/2966126', 'title': 'LinkedIn'}, {'url': 'http://www.cnbc.com/http://www.youtube.com/user/CNBCInternational', 'title': 'Youtube'}, {'url': 'http://www.cnbc.com/http://www.cnbc.com/id/28295763', 'title': 'RSS'}, {'url': 'http://www.cnbc.com/pre-markets/', 'title': 'Pre-markets'}, {'url': 'http://www.cnbc.com/http://www.cnbc.com/world-markets-heat-map/', 'title': 'World stock markets heat map'}, {'url': 'http://www.cnbc.com/dow-components/', 'title': 'Dow 30: Real-time quotes'}, {'url': 'http://www.cnbc.com/http://data.cnbc.com/quotes/aapl%2Caxp%2Cba%2Ccat%2Ccsco%2Ccvx%2Cdd%2Cdis%2Cge%2Cgs%2Chd%2Cibm%2Cintc%2Cjnj%2Cjpm%2Cko%2Cmcd%2Cmmm%2Cmrk%2Cmsft%2Cnke%2Cpfe%2Cpg%2Ctrv%2Cunh%2Cutx%2Cv%2Cvz%2Cwmt%2Cxom', 'title': 'Dow 30: After-hours quotes'}, {'url': 'http://www.cnbc.com/sectors/', 'title': 'Sector watch'}, {'url': 'http://www.cnbc.com/2017/03/28/dollar-bounces-on-fed-talk-sterling-wobbles-on-brexit-anxiety.html', 'title': 'Dollar bounces on Fed talk, sterling wobbles on Brexit anxiety'}, {'url': 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'title': "Le Pen victory could be five times as perilous as Greece's financial crisis: UBS"}, {'url': 'http://www.cnbc.com/2017/03/28/iran-says-russia-can-use-its-military-bases-on-case-by-case-basis.html', 'title': "Iran says Russia can use its military bases 'on case by case basis'"}, {'url': 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'title': u'UK introduces super secure new \xa31 coin'}, {'url': 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'title': 'Google Home A.I. speaker is coming to the UK to challenge Amazon Echo'}, {'url': 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'title': 'Nuclear nonproliferation: Lessons from Myanmar'}, {'url': 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'title': 'North Korea could be in final stages of nuclear test preparations: Report'}, {'url': 'http://www.cnbc.com/2017/03/28/hootsuite-ceo-talks-social-media-and-trump.html', 'title': 'Companies need top-down approach to social media: Hootsuite CEO'}, {'url': 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'title': 'Tesla deal boosts Chinese presence in US auto tech'}, {'url': 'http://www.cnbc.com/2017/03/28/dow-trump-dollar-kushner-stoxx-wallstreet.html', 'title': 'Reaction: Global markets stepped past Trump wobble on Obamacare'}, {'url': 'http://www.cnbc.com/2017/03/27/trump-brexit-healthcare-russia-dow-stoxx.html', 'title': 'Reaction: Risk-off hits markets after Trump fails to pass Obamacare hurdle'}, {'url': 'http://www.cnbc.com/2017/03/24/trump-healthcare-markets-us-dow-stocks.html', 'title': 'Reaction: Wall Street stocks move higher as investors countdown to health-care vote'}, {'url': 'http://www.cnbc.com/2017/03/23/trump-london-terrorism-markets-stocks-dow-ftse-may-uk-us.html', 'title': 'Reaction: London police name attacker in Westminster terrorist incident'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000603723', 'title': "Weekly Agenda: From EU visas to 'Fearless Girl'"}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000602217', 'title': 'Weekly Agenda: From the Canadian budget to the Boao Forum'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000600643', 'title': "Weekly Agenda: From Merkel's US visit to the FOMC meeting"}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000598102', 'title': "Weekly Agenda: From 'mini' EU summit to US daylight saving"}, {'url': 'http://www.cnbc.com/2017/03/26/trader-poll-which-will-garner-the-most-market-attention.html', 'title': 'Trader poll: Which will garner the most market attention?'}, {'url': 'http://www.cnbc.com/2017/03/20/trader-poll-what-are-chinas-greatest-challenges.html', 'title': u'Trader poll: What are China\u2019s greatest challenges?'}, {'url': 'http://www.cnbc.com/2017/03/12/trader-poll-is-the-fed-definitely-going-to-hike-rates-at-this-meeting.html', 'title': 'Trader Poll: Is the Fed definitely going to hike rates at this meeting?'}, {'url': 'http://www.cnbc.com/2017/03/06/trader-poll-has-the-us-dollar-got-higher-to-go.html', 'title': 'Trader poll: Has the US dollar got higher to go?'}, {'url': 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'title': 'This ad agency is standing against xenophobia; using name of its Jewish founders'}, {'url': 'http://www.cnbc.com/advertorial/2017/03/09/breathing-new-life-into-brands.html', 'title': 'Breathing new life into brands'}, {'url': 'http://www.cnbc.com/2017/03/23/make-sure-youre-not-replaced-by-a-machine-microsoft-us-chief-marketer.html', 'title': "Make sure you're not replaced by a machine: Microsoft US chief marketer"}, {'url': 'http://www.cnbc.com/2017/03/23/online-ads-need-to-stop-being-intrusive-eurosport.html', 'title': 'Online ads need to stop being intrusive, especially around 2018 Olympics: Eurosport MD'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595689', 'title': 'Why naming a product is so important'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595687', 'title': u'\u2018Building up a sofa\u2019 that\u2019s fits customer needs: Matthew\u2019s brand proposal'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595688', 'title': u'A men\u2019s \u2018grooming brand with an organic twist\u2019: Connor\u2019s proposal'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595690', 'title': 'Why passion is the true driver of a successful entrepreneur'}, {'url': 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'title': "'Major' solar project gets the green light in Northern Ireland"}, {'url': 'http://www.cnbc.com/2017/03/23/engineers-develop-solar-powered-skin-which-could-transform-lives.html', 'title': "Engineers develop solar powered 'skin' which could transform lives"}, {'url': 'http://www.cnbc.com/2017/03/23/palm-oil-its-uses-and-ways-to-limit-its-impact.html', 'title': 'Palm oil: Its uses and ways to limit its impact'}, {'url': 'http://www.cnbc.com/advertorial/2017/03/13/access-to-energy-when-business-issues-meet-social-impacts.html', 'title': 'Access to energy: When business issues meet social impacts'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'title': u"Jack Dorsey: I'll do \u2018whatever it takes\u2019 for Twitter, Square to succeed"}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'title': u'Is the US government ready for the impact of AI? \u2018I don\u2019t know,\u2019 Twitter CEO Jack Dorsey says'}, {'url': 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'title': 'Square launches in UK, CEO Jack Dorsey says on the lookout for AI firms to acquire'}, {'url': 'http://www.cnbc.com/2017/03/28/amazon-to-acquire-souqcom-a-large-e-commerce-site-in-the-middle-east.html', 'title': 'Amazon reaches deal to acquire Middle East e-commerce site Souq.com'}, {'url': 'http://www.cnbc.com/advertorial/2016/12/13/a-new-era-of-intelligent-machinery.html', 'title': 'A new era of intelligent machinery'}, {'url': 'http://www.cnbc.com/advertorial/2016/12/05/the-reimagining-of-cities.html', 'title': 'The reimagining of cities'}, {'url': 'http://www.cnbc.com/advertorial/2016/11/22/could-mining-asteroids-save-earth.html', 'title': 'Could mining asteroids save Earth?'}, {'url': 'http://www.cnbc.com/advertorial/2016/11/02/smarter-ships-safer-seas.html', 'title': 'At sea, every hour is rush hour. Are autonomous ships the solution?'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'title': u'Is the US government ready for the impact of AI? \u2018I don\u2019t know,\u2019 Twitter CEO says'}]
</code>```

You can refer to documentation of scraping and lxml for more understanding.

Body:
I am trying to do a Web-Crawling project, and I am keep on getting an error code called "'list' object has no attribute 'xpath'"/

This is the code so far:

import requests
from lxml import html
import pandas

url = "http://www.cnbc.com/"
response = requests.get(url)
doc = html.fromstring(response.text)

headlineNode = doc.xpath('//div[@class="headline"]')
len(headlineNode)

headlines = headlineNode.xpath('/a')
len(headlines)

I want to extraxt the headlines from CNBC Home, but I am keep on getting an error saying

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-d9f54582133c> in <module>()
----> 1 headlines = headlineNode.xpath('/a')
      2 len(headlines)

AttributeError: 'list' object has no attribute 'xpath'

Is there anyway to fix this?

Body:
The reason you are getting this error is because xpath always results a list of elements and xpath can be called on elements.

So to get expected results, what you can do is iterate over the headlineNode list and then call the xpath to the element nodes such as node.xpath('/a')

The following code will give you the list of all the url you needed as a list. You can do something like this :

import requests
from lxml import html
import pandas

url = "http://www.cnbc.com/"
response = requests.get(url)
doc = html.fromstring(response.text)

headlineNode = doc.xpath('//div[@class="headline"]')
len(headlineNode)

url_list  = []
for node in headlineNode :
    url_node = node.xpath('./a/@href')
    if url_node :
        url_list.append(url + url_node[0].strip())
print(url_list)
len(url_list)

This will result in :

['http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'http://www.cnbc.com/2017/03/28/us-markets.html', 'http://www.cnbc.com/2017/03/28/european-markets-investors-shrug-off-trump-concerns.html', 'http://www.cnbc.com/2017/03/27/gold-steady-as-dollar-edges-up-focus-on-trump-agenda.html', 'http://www.cnbc.com/2017/03/27/weaker-dollar-lifts-oil-futures-but-soaring-us-output-weighs.html', 'http://www.cnbc.com/2017/03/28/us-treasurys-edge-lower-as-investors-eye-data-auctions.html', 'http://www.cnbc.com/2017/03/27/dollar-limps-away-from-multi-month-lows-still-seen-vulnerable.html', 'http://www.cnbc.com/2017/03/27/dollar-limps-away-from-multi-month-lows-still-seen-vulnerable.html', 'http://www.cnbc.com/2017/03/28/markets-could-see-heartbreak-if-brexit-is-hard-to-do.html', 'http://www.cnbc.com/2017/03/28/former-google-exec-heres-how-to-know-its-time-to-fire-an-employee.html', 'http://www.cnbc.com/2017/03/28/chinas-secret-plan-to-crush-spacex-and-the-us-space-program.html', 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'http://www.cnbc.com/2017/03/28/following-tuesdays-rally-stocks-will-grind-higher-into-2018-analyst-says.html', 'http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'http://www.cnbc.com/2017/03/28/made-in-america-impossible-tech-startups.html', 'http://www.cnbc.com/2017/03/28/toshibas-westinghouse-to-file-for-us-bankruptcy-sources.html', 'http://www.cnbc.com/2017/03/28/early-reports-of-damage-in-wake-of-australias-cyclone-debbie.html', 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'http://www.cnbc.com/2017/03/28/rodrigo-duterte-turns-72-a-look-at-his-controversial-presidency-so-far-commentary.html', 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'http://www.cnbc.com/2017/03/28/congress-clears-way-for-isps-to-sell-browsing-history.html', 'http://www.cnbc.com/2017/03/28/british-pm-may-to-fire-starting-gun-on-brexit.html', 'http://www.cnbc.com/2017/03/28/brexit-is-like-arthritis-it-doesnt-kill-you-but-it-hits-you-says-former-boe-member.html', 'http://www.cnbc.com/2017/03/27/florida-preparesfor-xi-jinpingsvisit.html', 'http://www.cnbc.com/2017/03/28/us-heading-for-recession-after-2-years-of-unsustainable-growth-economist-says.html', 'http://www.cnbc.com/2017/03/28/this-is-what-immigration-means-to-the-us-economy-in-two-charts.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'http://www.cnbc.com/2017/03/28/next-iphone-is-last-hurrah-for-smartphones-apple.html', 'http://www.cnbc.com/2017/03/28/south-africa-speculates-over-possible-firing-of-finance-minister.html', 'http://www.cnbc.com/2017/03/28/snap-was-a-drunk-at-the-wheel-but-now-looks-like-a-very-real-business-fund-manager-says.html', 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'http://www.cnbc.com/2017/03/28/siemens-medical-solutions-wins-41-billion-us-defense-contract.html', 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'http://www.cnbc.com/2017/03/28/trump-to-meet-egyptian-president-at-white-house-on-april-3.html', 'http://www.cnbc.com/2017/03/28/tesla-is-rejecting-a-racial-harassment-lawsuit-filed-by-an-assembly-line-worker.html', 'http://www.cnbc.com/2017/03/28/jpmorgan-says-markets-are-underestimating-the-upside-of-asian-banks.html', 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'http://www.cnbc.com/https://www.facebook.com/cnbcinternational/', 'http://www.cnbc.com/https://twitter.com/cnbcworld', 'http://www.cnbc.com/http://www.linkedin.com/company/2966126', 'http://www.cnbc.com/http://www.youtube.com/user/CNBCInternational', 'http://www.cnbc.com/http://www.cnbc.com/id/28295763', 'http://www.cnbc.com/pre-markets/', 'http://www.cnbc.com/http://www.cnbc.com/world-markets-heat-map/', 'http://www.cnbc.com/dow-components/', 'http://www.cnbc.com/http://data.cnbc.com/quotes/aapl%2Caxp%2Cba%2Ccat%2Ccsco%2Ccvx%2Cdd%2Cdis%2Cge%2Cgs%2Chd%2Cibm%2Cintc%2Cjnj%2Cjpm%2Cko%2Cmcd%2Cmmm%2Cmrk%2Cmsft%2Cnke%2Cpfe%2Cpg%2Ctrv%2Cunh%2Cutx%2Cv%2Cvz%2Cwmt%2Cxom', 'http://www.cnbc.com/sectors/', 'http://www.cnbc.com/2017/03/27/dollar-limps-away-from-multi-month-lows-still-seen-vulnerable.html', 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'http://www.cnbc.com/2017/03/28/iran-says-russia-can-use-its-military-bases-on-case-by-case-basis.html', 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'http://www.cnbc.com/2017/03/28/hootsuite-ceo-talks-social-media-and-trump.html', 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'http://www.cnbc.com/2017/03/28/dow-trump-dollar-kushner-stoxx-wallstreet.html', 'http://www.cnbc.com/2017/03/27/trump-brexit-healthcare-russia-dow-stoxx.html', 'http://www.cnbc.com/2017/03/24/trump-healthcare-markets-us-dow-stocks.html', 'http://www.cnbc.com/2017/03/23/trump-london-terrorism-markets-stocks-dow-ftse-may-uk-us.html', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000603723', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000602217', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000600643', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000598102', 'http://www.cnbc.com/2017/03/26/trader-poll-which-will-garner-the-most-market-attention.html', 'http://www.cnbc.com/2017/03/20/trader-poll-what-are-chinas-greatest-challenges.html', 'http://www.cnbc.com/2017/03/12/trader-poll-is-the-fed-definitely-going-to-hike-rates-at-this-meeting.html', 'http://www.cnbc.com/2017/03/06/trader-poll-has-the-us-dollar-got-higher-to-go.html', 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'http://www.cnbc.com/advertorial/2017/03/09/breathing-new-life-into-brands.html', 'http://www.cnbc.com/2017/03/23/make-sure-youre-not-replaced-by-a-machine-microsoft-us-chief-marketer.html', 'http://www.cnbc.com/2017/03/23/online-ads-need-to-stop-being-intrusive-eurosport.html', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595689', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595687', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595688', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595690', 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'http://www.cnbc.com/2017/03/23/engineers-develop-solar-powered-skin-which-could-transform-lives.html', 'http://www.cnbc.com/2017/03/23/palm-oil-its-uses-and-ways-to-limit-its-impact.html', 'http://www.cnbc.com/advertorial/2017/03/13/access-to-energy-when-business-issues-meet-social-impacts.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'http://www.cnbc.com/2017/03/28/amazon-to-acquire-souqcom-a-large-e-commerce-site-in-the-middle-east.html', 'http://www.cnbc.com/advertorial/2016/12/13/a-new-era-of-intelligent-machinery.html', 'http://www.cnbc.com/advertorial/2016/12/05/the-reimagining-of-cities.html', 'http://www.cnbc.com/advertorial/2016/11/22/could-mining-asteroids-save-earth.html', 'http://www.cnbc.com/advertorial/2016/11/02/smarter-ships-safer-seas.html', 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'http://www.cnbc.com/2017/03/28/risk-of-correction-quite-high-but-wont-kill-bull-market-says-goldman-sachs-strategist.html', 'http://www.cnbc.com/2017/03/28/samsung-galaxy-s8-apple-iphone-8-launch.html', 'http://www.cnbc.com/2017/03/28/made-in-america-impossible-tech-startups.html', 'http://www.cnbc.com/2017/03/28/facebook-stole-these-features-from-snapchat.html', 'http://www.cnbc.com/2017/03/28/cisco-separating-some-key-networking-software-from-hardware--report.html', 'http://www.cnbc.com/2017/03/28/uber-releases-diversity-report-and-repudiates-its-hard-charging-attitude.html', 'http://www.cnbc.com/2017/03/28/cramers-charts-explain-why-general-mills-looks-ripe-for-a-run.html', 'http://www.cnbc.com/2017/03/28/cramer-why-it-might-be-time-for-you-to-unfollow-trumps-twitter-feed.html', 'http://www.cnbc.com/2017/03/28/blackrock-plans-major-changes-to-its-active-stockpicking-business.html', 'http://www.cnbc.com/2017/03/28/darden-shares-pop-4-percent-on-strong-earnings-beat-cheddars-acquisition.html', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605169', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605171', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605046', 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000605164', 'http://www.cnbc.com/2017/03/28/nunes-seems-like-the-wrong-person-to-lead-trump-russia-probe-commentary.html', 'http://www.cnbc.com/2017/03/28/donald-trump-is-making-his-russia-scandal-about-clintons-commentary.html', 'http://www.cnbc.com/2017/03/28/self-made-millionaire-shares-3-tricks-for-raising-successful-kids.html', 'http://www.cnbc.com/2017/03/28/president-trump-is-directing-his-anger-at-the-wrong-people-commentary.html']

To add title also to the result_list, you can modify it something like this :

import requests
from lxml import html
import pandas

url = "http://www.cnbc.com/"
response = requests.get(url)
doc = html.fromstring(response.text)

headlineNode = doc.xpath('//div[@class="headline"]')
len(headlineNode)

result_list  = []
for node in headlineNode :
    url_node = node.xpath('./a/@href')
    title = node.xpath('./a/text()')
    if (url_node and title) :
        result_list.append({'url' : url + url_node[0].strip(),
            'title' : title[0].strip()})
print(result_list)
len(result_list)

This will result in :

[{'url': 'http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'title': 'Asia up higher after Dow breaks 8-day losing streak, Brexit ahead'}, {'url': 'http://www.cnbc.com/2017/03/28/us-markets.html', 'title': 'Dow snaps 8-day losing streak as consumer confidence surges; financials lead'}, {'url': 'http://www.cnbc.com/2017/03/28/european-markets-investors-shrug-off-trump-concerns.html', 'title': 'European stocks close higher as investors shrug off Trump concerns; Wolseley up 5%'}, {'url': 'http://www.cnbc.com/2017/03/27/gold-steady-as-dollar-edges-up-focus-on-trump-agenda.html', 'title': 'Gold rises as investors focus on Trump agenda'}, {'url': 'http://www.cnbc.com/2017/03/27/weaker-dollar-lifts-oil-futures-but-soaring-us-output-weighs.html', 'title': 'US crude settles at $48.37, rising 64 cents with Libyan output disruption'}, {'url': 'http://www.cnbc.com/2017/03/28/us-treasurys-edge-lower-as-investors-eye-data-auctions.html', 'title': 'US Treasurys mostly higher as investors digest data, 5-year note auction'}, {'url': 'http://www.cnbc.com/2017/03/28/dollar-bounces-on-fed-talk-sterling-wobbles-on-brexit-anxiety.html', 'title': 'Dollar bounces on Fed talk, sterling wobbles on Brexit anxiety'}, {'url': 'http://www.cnbc.com/2017/03/28/dollar-bounces-on-fed-talk-sterling-wobbles-on-brexit-anxiety.html', 'title': 'Dollar bounces on Fed talk, sterling wobbles on Brexit anxiety'}, {'url': 'http://www.cnbc.com/2017/03/28/markets-could-see-heartbreak-if-brexit-is-hard-to-do.html', 'title': 'Markets could see heartbreak if Brexit is hard to do'}, {'url': 'http://www.cnbc.com/2017/03/28/former-google-exec-heres-how-to-know-its-time-to-fire-an-employee.html', 'title': "Former Google exec: Here's how to know it's time to fire an employee"}, {'url': 'http://www.cnbc.com/2017/03/28/chinas-secret-plan-to-crush-spacex-and-the-us-space-program.html', 'title': "China's secret plan to crush SpaceX and the US space program"}, {'url': 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'title': "Le Pen victory could be five times as dangerous as Greece's financial meltdown: UBS"}, {'url': 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'title': 'How this tiny country went from nuclear problem child to role model'}, {'url': 'http://www.cnbc.com/2017/03/28/following-tuesdays-rally-stocks-will-grind-higher-into-2018-analyst-says.html', 'title': "Following Tuesday's rally, stocks will 'grind higher' into 2018, analyst says"}, {'url': 'http://www.cnbc.com/2017/03/28/asia-markets-to-watch-brexit-news-dollar-movements-oil-prices.html', 'title': 'Asia up higher after Dow breaks 8-day losing streak, Brexit ahead'}, {'url': 'http://www.cnbc.com/2017/03/28/made-in-america-impossible-tech-startups.html', 'title': "These three start-ups show why it's so hard to build products in America"}, {'url': 'http://www.cnbc.com/2017/03/28/japans-tepid-retail-sales-raise-concerns-about-consumption-growth.html', 'title': "Japan's tepid retail sales raise concerns about consumption, growth"}, {'url': 'http://www.cnbc.com/2017/03/28/toshibas-westinghouse-to-file-for-us-bankruptcy-sources.html', 'title': "Toshiba's Westinghouse to file for US bankruptcy: Sources"}, {'url': 'http://www.cnbc.com/2017/03/28/early-reports-of-damage-in-wake-of-australias-cyclone-debbie.html', 'title': "Early reports of damage in wake of Australia's Cyclone Debbie"}, {'url': 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'title': 'Tesla deal boosts Chinese presence in US auto tech'}, {'url': 'http://www.cnbc.com/2017/03/28/rodrigo-duterte-turns-72-a-look-at-his-controversial-presidency-so-far-commentary.html', 'title': 'As Rodrigo Duterte turns 72, a look at his controversial presidency so far'}, {'url': 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'title': 'North Korea could be in final stages of nuclear test preparations: Report'}, {'url': 'http://www.cnbc.com/2017/03/28/congress-clears-way-for-isps-to-sell-browsing-history.html', 'title': 'Congress just cleared the way for internet providers to sell your web browsing history'}, {'url': 'http://www.cnbc.com/2017/03/28/british-pm-may-to-fire-starting-gun-on-brexit.html', 'title': 'British PM May to fire starting gun on Brexit'}, {'url': 'http://www.cnbc.com/2017/03/28/brexit-is-like-arthritis-it-doesnt-kill-you-but-it-hits-you-says-former-boe-member.html', 'title': u'Brexit is like arthritis, it doesn\u2019t kill you but it hits you, says former BOE member'}, {'url': 'http://www.cnbc.com/2017/03/27/florida-preparesfor-xi-jinpingsvisit.html', 'title': u"Florida authorities prep\xa0for Xi Jinping's\xa0visit"}, {'url': 'http://www.cnbc.com/2017/03/28/us-heading-for-recession-after-2-years-of-unsustainable-growth-economist-says.html', 'title': 'US heading for recession after 2 years of unsustainable growth, economist says'}, {'url': 'http://www.cnbc.com/2017/03/28/this-is-what-immigration-means-to-the-us-economy-in-two-charts.html', 'title': 'This is what immigration means to the U.S. economy in two charts'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'title': u'Jack Dorsey brushes off calls to quit as CEO, says will do \u2018whatever it takes\u2019 for Twitter, Square to succeed'}, {'url': 'http://www.cnbc.com/2017/03/28/next-iphone-is-last-hurrah-for-smartphones-apple.html', 'title': 'The next iPhone is the last hurrah for smartphones: Fund manager'}, {'url': 'http://www.cnbc.com/2017/03/28/south-africa-speculates-over-possible-firing-of-finance-minister.html', 'title': 'South Africa faces uncertain wait amid speculation finance minister is to be fired'}, {'url': 'http://www.cnbc.com/2017/03/28/snap-was-a-drunk-at-the-wheel-but-now-looks-like-a-very-real-business-fund-manager-says.html', 'title': "Snap was a 'drunk at the wheel' but now looks like a very real business, fund manager says"}, {'url': 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'title': 'This ad agency is standing against xenophobia and rebranding with the name of its Jewish founders'}, {'url': 'http://www.cnbc.com/2017/03/28/siemens-medical-solutions-wins-41-billion-us-defense-contract.html', 'title': 'Siemens Medical Solutions wins $4.1 billion US defense contract'}, {'url': 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'title': 'Google Home A.I. speaker is coming to the UK to challenge Amazon Echo'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'title': u'Is the US government ready for the impact of AI? \u2018I don\u2019t know,\u2019 Twitter CEO Jack Dorsey says'}, {'url': 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'title': u'UK introduces super secure new \xa31 coin'}, {'url': 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'title': "'Major' solar project gets the green light in Northern Ireland"}, {'url': 'http://www.cnbc.com/2017/03/28/trump-to-meet-egyptian-president-at-white-house-on-april-3.html', 'title': 'Trump to meet Egyptian president at White House on April 3'}, {'url': 'http://www.cnbc.com/2017/03/28/tesla-is-rejecting-a-racial-harassment-lawsuit-filed-by-an-assembly-line-worker.html', 'title': 'Tesla rejects racial harassment lawsuit filed by assembly line worker'}, {'url': 'http://www.cnbc.com/2017/03/28/jpmorgan-says-markets-are-underestimating-the-upside-of-asian-banks.html', 'title': 'JPMorgan says markets are underestimating the upside of Asian banks'}, {'url': 'http://www.cnbc.com/https://www.facebook.com/cnbcinternational/', 'title': 'Facebook'}, {'url': 'http://www.cnbc.com/https://twitter.com/cnbcworld', 'title': 'Twitter'}, {'url': 'http://www.cnbc.com/http://www.linkedin.com/company/2966126', 'title': 'LinkedIn'}, {'url': 'http://www.cnbc.com/http://www.youtube.com/user/CNBCInternational', 'title': 'Youtube'}, {'url': 'http://www.cnbc.com/http://www.cnbc.com/id/28295763', 'title': 'RSS'}, {'url': 'http://www.cnbc.com/pre-markets/', 'title': 'Pre-markets'}, {'url': 'http://www.cnbc.com/http://www.cnbc.com/world-markets-heat-map/', 'title': 'World stock markets heat map'}, {'url': 'http://www.cnbc.com/dow-components/', 'title': 'Dow 30: Real-time quotes'}, {'url': 'http://www.cnbc.com/http://data.cnbc.com/quotes/aapl%2Caxp%2Cba%2Ccat%2Ccsco%2Ccvx%2Cdd%2Cdis%2Cge%2Cgs%2Chd%2Cibm%2Cintc%2Cjnj%2Cjpm%2Cko%2Cmcd%2Cmmm%2Cmrk%2Cmsft%2Cnke%2Cpfe%2Cpg%2Ctrv%2Cunh%2Cutx%2Cv%2Cvz%2Cwmt%2Cxom', 'title': 'Dow 30: After-hours quotes'}, {'url': 'http://www.cnbc.com/sectors/', 'title': 'Sector watch'}, {'url': 'http://www.cnbc.com/2017/03/28/dollar-bounces-on-fed-talk-sterling-wobbles-on-brexit-anxiety.html', 'title': 'Dollar bounces on Fed talk, sterling wobbles on Brexit anxiety'}, {'url': 'http://www.cnbc.com/2017/03/28/le-pen-victory-could-be-five-times-as-dangerous-as-greeces-financial-meltdown-ubs.html', 'title': "Le Pen victory could be five times as perilous as Greece's financial crisis: UBS"}, {'url': 'http://www.cnbc.com/2017/03/28/iran-says-russia-can-use-its-military-bases-on-case-by-case-basis.html', 'title': "Iran says Russia can use its military bases 'on case by case basis'"}, {'url': 'http://www.cnbc.com/2017/03/28/uk-introduces-super-secure-new-one-pound-coin.html', 'title': u'UK introduces super secure new \xa31 coin'}, {'url': 'http://www.cnbc.com/2017/03/28/google-home-ai-speaker-is-coming-to-the-uk-to-challenge-amazon-echo.html', 'title': 'Google Home A.I. speaker is coming to the UK to challenge Amazon Echo'}, {'url': 'http://www.cnbc.com/2017/03/28/nuclear-nonproliferation-lessons-from-myanmar.html', 'title': 'Nuclear nonproliferation: Lessons from Myanmar'}, {'url': 'http://www.cnbc.com/2017/03/28/north-korea-could-be-in-final-stages-of-nuclear-test-preparations-report.html', 'title': 'North Korea could be in final stages of nuclear test preparations: Report'}, {'url': 'http://www.cnbc.com/2017/03/28/hootsuite-ceo-talks-social-media-and-trump.html', 'title': 'Companies need top-down approach to social media: Hootsuite CEO'}, {'url': 'http://www.cnbc.com/2017/03/28/messaging-app-parent-tencent-takes-stake-in-tesla.html', 'title': 'Tesla deal boosts Chinese presence in US auto tech'}, {'url': 'http://www.cnbc.com/2017/03/28/dow-trump-dollar-kushner-stoxx-wallstreet.html', 'title': 'Reaction: Global markets stepped past Trump wobble on Obamacare'}, {'url': 'http://www.cnbc.com/2017/03/27/trump-brexit-healthcare-russia-dow-stoxx.html', 'title': 'Reaction: Risk-off hits markets after Trump fails to pass Obamacare hurdle'}, {'url': 'http://www.cnbc.com/2017/03/24/trump-healthcare-markets-us-dow-stocks.html', 'title': 'Reaction: Wall Street stocks move higher as investors countdown to health-care vote'}, {'url': 'http://www.cnbc.com/2017/03/23/trump-london-terrorism-markets-stocks-dow-ftse-may-uk-us.html', 'title': 'Reaction: London police name attacker in Westminster terrorist incident'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000603723', 'title': "Weekly Agenda: From EU visas to 'Fearless Girl'"}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000602217', 'title': 'Weekly Agenda: From the Canadian budget to the Boao Forum'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000600643', 'title': "Weekly Agenda: From Merkel's US visit to the FOMC meeting"}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000598102', 'title': "Weekly Agenda: From 'mini' EU summit to US daylight saving"}, {'url': 'http://www.cnbc.com/2017/03/26/trader-poll-which-will-garner-the-most-market-attention.html', 'title': 'Trader poll: Which will garner the most market attention?'}, {'url': 'http://www.cnbc.com/2017/03/20/trader-poll-what-are-chinas-greatest-challenges.html', 'title': u'Trader poll: What are China\u2019s greatest challenges?'}, {'url': 'http://www.cnbc.com/2017/03/12/trader-poll-is-the-fed-definitely-going-to-hike-rates-at-this-meeting.html', 'title': 'Trader Poll: Is the Fed definitely going to hike rates at this meeting?'}, {'url': 'http://www.cnbc.com/2017/03/06/trader-poll-has-the-us-dollar-got-higher-to-go.html', 'title': 'Trader poll: Has the US dollar got higher to go?'}, {'url': 'http://www.cnbc.com/2017/03/28/this-ad-agency-is-rebranding-with-the-name-of-its-jewish-founders.html', 'title': 'This ad agency is standing against xenophobia; using name of its Jewish founders'}, {'url': 'http://www.cnbc.com/advertorial/2017/03/09/breathing-new-life-into-brands.html', 'title': 'Breathing new life into brands'}, {'url': 'http://www.cnbc.com/2017/03/23/make-sure-youre-not-replaced-by-a-machine-microsoft-us-chief-marketer.html', 'title': "Make sure you're not replaced by a machine: Microsoft US chief marketer"}, {'url': 'http://www.cnbc.com/2017/03/23/online-ads-need-to-stop-being-intrusive-eurosport.html', 'title': 'Online ads need to stop being intrusive, especially around 2018 Olympics: Eurosport MD'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595689', 'title': 'Why naming a product is so important'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595687', 'title': u'\u2018Building up a sofa\u2019 that\u2019s fits customer needs: Matthew\u2019s brand proposal'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595688', 'title': u'A men\u2019s \u2018grooming brand with an organic twist\u2019: Connor\u2019s proposal'}, {'url': 'http://www.cnbc.com/http://video.cnbc.com/gallery/?video=3000595690', 'title': 'Why passion is the true driver of a successful entrepreneur'}, {'url': 'http://www.cnbc.com/2017/03/28/major-solar-project-gets-the-green-light-in-northern-ireland.html', 'title': "'Major' solar project gets the green light in Northern Ireland"}, {'url': 'http://www.cnbc.com/2017/03/23/engineers-develop-solar-powered-skin-which-could-transform-lives.html', 'title': "Engineers develop solar powered 'skin' which could transform lives"}, {'url': 'http://www.cnbc.com/2017/03/23/palm-oil-its-uses-and-ways-to-limit-its-impact.html', 'title': 'Palm oil: Its uses and ways to limit its impact'}, {'url': 'http://www.cnbc.com/advertorial/2017/03/13/access-to-energy-when-business-issues-meet-social-impacts.html', 'title': 'Access to energy: When business issues meet social impacts'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ceo-calls-to-step-down.html', 'title': u"Jack Dorsey: I'll do \u2018whatever it takes\u2019 for Twitter, Square to succeed"}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'title': u'Is the US government ready for the impact of AI? \u2018I don\u2019t know,\u2019 Twitter CEO Jack Dorsey says'}, {'url': 'http://www.cnbc.com/2017/03/28/square-uk-launch-ceo-jack-dorsey-ai-acquisitions.html', 'title': 'Square launches in UK, CEO Jack Dorsey says on the lookout for AI firms to acquire'}, {'url': 'http://www.cnbc.com/2017/03/28/amazon-to-acquire-souqcom-a-large-e-commerce-site-in-the-middle-east.html', 'title': 'Amazon reaches deal to acquire Middle East e-commerce site Souq.com'}, {'url': 'http://www.cnbc.com/advertorial/2016/12/13/a-new-era-of-intelligent-machinery.html', 'title': 'A new era of intelligent machinery'}, {'url': 'http://www.cnbc.com/advertorial/2016/12/05/the-reimagining-of-cities.html', 'title': 'The reimagining of cities'}, {'url': 'http://www.cnbc.com/advertorial/2016/11/22/could-mining-asteroids-save-earth.html', 'title': 'Could mining asteroids save Earth?'}, {'url': 'http://www.cnbc.com/advertorial/2016/11/02/smarter-ships-safer-seas.html', 'title': 'At sea, every hour is rush hour. Are autonomous ships the solution?'}, {'url': 'http://www.cnbc.com/2017/03/28/jack-dorsey-twitter-ai-impact-jobs-mnuchin-government.html', 'title': u'Is the US government ready for the impact of AI? \u2018I don\u2019t know,\u2019 Twitter CEO says'}]

You can refer to documentation of scraping and lxml for more understanding.