今天我在玩 BeautifulSoup 和 Requests API。所以我想我会写一个简单的爬虫,它会跟随深度为 2 的链接(如果这有意义的话)。我正在抓取的网页中的所有链接都是相对的。(例如:)<a href="/free-man-aman-sethi/books/9788184001341.htm" title="A Free Man">
所以为了让它们绝对,我想我会使用urljoin
.
为此,我必须首先从<a>
标签中提取 href 值,为此我认为我会使用split
:
#!/bin/python
#crawl.py
import requests
from bs4 import BeautifulSoup
from urlparse import urljoin
html_source=requests.get("http://www.flipkart.com/books")
soup=BeautifulSoup(html_source.content)
links=soup.find_all("a")
temp=links[0].split('"')
这给出了以下错误:
Traceback (most recent call last):
File "test.py", line 10, in <module>
temp=links[0].split('"')
TypeError: 'NoneType' object is not callable
在正确阅读文档之前潜入水中,我意识到这可能不是实现我的目标的最佳方式,但为什么会有 TypeError?