Python Subredits的beautifulsoup
我一直在尝试使用BeautifulSoup学习一些html解析,并尝试让它为reddit工作。这是我的密码Python Subredits的beautifulsoup,python,html-parsing,beautifulsoup,reddit,Python,Html Parsing,Beautifulsoup,Reddit,我一直在尝试使用BeautifulSoup学习一些html解析,并尝试让它为reddit工作。这是我的密码 !/usr/bin/python import BeautifulSoup from BeautifulSoup import BeautifulSoup as BSoup import os, re, sys, math, os.path, urllib, string, random, time url = urllib.urlopen(sys.argv[1]).read()
!/usr/bin/python
import BeautifulSoup
from BeautifulSoup import BeautifulSoup as BSoup
import os, re, sys, math, os.path, urllib, string, random, time
url = urllib.urlopen(sys.argv[1]).read()
soup= BSoup(url)
links = []
for link in soup.findAll('a',attrs={'class':'comments may-blank'}):
links.append(link.get("href"))
print links
我已经为r/gaming和r/worldnews成功地测试了代码,但是r/GIF的代码失败了。我还验证了所有子Reddit都使用了相同的类。而且我也试过了
for link in soup.findAll('a'):
但代码仍然无法找到超链接。任何关于为什么会发生这种情况以及如何使代码与所有子插件一起工作的建议。如果您经常这样做,您会遇到这种情况
As a reminder to developers, we recommend that clients make no
more than <a href="http://github.com/reddit/reddit/wiki/API">one
request every two seconds</a> to avoid seeing this message.
作为对开发人员的提醒,我们建议客户端不要
不只是为了避免看到这条信息。
Reddit这样做是为了防止蜘蛛和爬虫的滥用
为您的请求留出空间,或者更好地使用它们的Python api:您能提供一个示例url吗?不要放弃Reddit。使用他们的API。在您使用python时,我还建议您查看我还建议升级到使用bs4