我尝试在这个链接中抓取结果:
当我用firebug检查它时,我可以看到html代码,我知道要提取tweets需要做什么。当我用html得到同样的问题时,不要用html。我只有标签。我错过了什么?在
下面的示例代码:
def get_tweets(section_url):
html = urlopen(section_url).read()
soup = BeautifulSoup(html, "lxml")
tweets = soup.find("div", "results")
category_links = [dd.a["href"] for tweet in tweets.findAll("div", "result-tweet")]
return category_links
url = "http://topsy.com/trackback?url=http%3A%2F%2Fmashable.com%2F2014%2F08%2F27%2Faustralia-retail-evolution-lab-aopen-shopping%2F"
cat_links = get_tweets(url)
谢谢, YB公司
问题是
results
div的内容被额外的HTTP调用和在浏览器端执行的javascript代码填满。urllib
只“看到”不包含所需数据的初始HTML页面。在一种选择是遵循@Himal的建议,模拟发送给} 模块^{} :
trackbacks.js
的底层请求,该请求通过tweets来获取数据。结果是JSON格式的,您可以使用标准库附带的^{印刷品:
^{pr2}$这是“下到金属”的选择。在
否则,你可以采取“高层次”的方法,而不必担心幕后发生了什么。让真正的浏览器加载您将通过selenium WebDriver与之交互的页面:
印刷品:
^{pr2}$这是如何缩放第二个选项以获取分页后的所有tweet:
相关问题 更多 >
编程相关推荐