我对python 2.7很新,但我试图从网站上获得一个简单的段落,但python输出[]。我设法提取数字而不是文本。
任何帮助都会很棒,谢谢。
<?php foreach ($records as $key => $record): ?>
<tr id="<?php echo $key; ?>">
<td><?php echo $record->parent_id; ?></td>
<td><?php echo $key; ?></td> //here I wish to get key starting from 0
<td><?php echo $record->title; ?></td>
</tr>
<?php endforeach; ?>
答案 0 :(得分:1)
使用BeautifulSoup
import urllib
from bs4 import BeautifulSoup
HTML_File = urllib.urlopen("http://uk.weather.com/weather/10day/New+Romney+KEN+United+Kingdom+UKXX1121:1:UK")
HTML_Text = HTML_File.read()
soup = BeautifulSoup(HTML_Text, 'html.parser')
print soup.select('.wx-timestamp')[0].text
输出:
Updated:
last updated about 20 minutes ago