In the code cell below, complete function extract163Data which takes a soup as a parameter and return a list whith the following data: {'title': '贾跃亭的成功意味着实体失败?', 'time': '2016-04-25 14:28:18', 'url': 'http://money.163.com/16/0425/14/BLGM1PH5002551G6.html'}, {'title': '海尔模式为何在西方叫好不叫座', 'time': '2016-04-22 15:00:23', 'url': 'http://money.163.com/16/0422/15/BL90MCB400253G87.html'}, {'title': '有前科就不能开网约车?', 'time': '2016-04-12 15:30:49', 'url': 'http://money.163.com/16/0412/15/BKFAETGB002552IJ.html'}.
时间: 2023-06-16 18:03:21 浏览: 107
extractData
Here is the implementation of the function:
```python
def extract163Data(soup):
data_list = []
news_list = soup.find('div', class_='mod_newslist').find_all('li')
for news in news_list:
title = news.find('a').get_text().strip()
time = news.find('span', class_='time').get_text().strip()
url = news.find('a')['href']
data = {'title': title, 'time': time, 'url': url}
data_list.append(data)
return data_list
```
This function first finds the `div` element with class `mod_newslist` using `soup.find`, and then gets all the `li` elements within it using `find_all`. For each `li` element, it extracts the `title`, `time`, and `url` using `find` and `get_text` methods, and then creates a dictionary with these values. Finally, it appends the dictionary to a list and returns the list.
阅读全文