请求,BeautifulSoup,无

时间:2014-07-13 21:27:05

标签: python beautifulsoup python-requests

出于某种原因,我似乎无法找到此代码打印的原因"无"。我直接从HTML复制/粘贴了ID ...提前致谢

import bs4
import json
import requests

URL = 'http://hypem.com/popular'

html = requests.get(URL).text
soup = bs4.BeautifulSoup(html)

print soup.find(id="displayList-data")

出于某种原因,当我改变了"请求"到" urllib2"

import bs4
import json
import urllib2

URL = 'http://hypem.com/popular/'

html = urllib2.urlopen(URL)
soup = bs4.BeautifulSoup(html)
data = soup.find(id="displayList-data")

print data

1 个答案:

答案 0 :(得分:0)

您粘贴的代码有效。但我怀疑你修改了你粘贴的代码与你在本地测试的代码相比,因为None听起来就像你直接从你打印到{ {1}}。相反,提取标记的内容,因为json.loads的文本表示包含find(id="...")标记。

<script>