python - 使用 Python 进行网页抓取

我想从网站获取每日日出/日落时间。是否可以使用 Python 抓取网页内容?使用了哪些模块?有教程吗?

最佳答案

将 urllib2 与出色的 BeautifulSoup 结合使用图书馆:

import urllib2
from BeautifulSoup import BeautifulSoup
# or if you're using BeautifulSoup4:
# from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen('http://example.com').read())

for row in soup('table', {'class': 'spad'})[0].tbody('tr'):
    tds = row('td')
    print tds[0].string, tds[1].string
    # will print date and sunrise

https://stackoverflow.com/questions/2081586/

相关文章:

linux - 查看 PS 命令的完整输出

python - 如何将 numpy 数组转换为(并显示)图像?

python - 如何消除数独方 block 中的凸性缺陷?

linux - 单个主机上的多个 glibc 库

mysql - 错误 1045 (28000) : Access denied for user '

linux - 如何在 Linux 中遍历目录?

linux - Bash中的 'eval'命令及其典型用途

python - 如果对象存在,我如何获取它,或者如果它在 Django 中不存在,我如何获取它?

python - scikit-learn 中跨多个列的标签编码

python - 如何检查我的 python 对象是否为数字?