hjhee / tiebaspider Goto Github PK
View Code? Open in Web Editor NEWfetch tieba posts
License: BSD 2-Clause "Simplified" License
fetch tieba posts
License: BSD 2-Clause "Simplified" License
首先十分感谢能提供这个工具,我是谷歌搜到bangumi然后找到这儿的。试了下面三个帖子链接发现了这个问题,即最后一页的楼中楼全都没有。
https://tieba.baidu.com/p/6216023968
https://tieba.baidu.com/p/6212415344
https://tieba.baidu.com/p/6209031748
我在.txt里记录了这四个链接,结果就打开tiebaspider之后就出现下面这样的error提示;不过文件倒是都生成了。(我不知道生成的有没有错误)
于是我把output文件夹清空了,这几个链接一个一个粘贴保存爬取,这次就没发现有下图这样的error提示。不知道什么情况,总之来这儿记录一下。
https://tieba.baidu.com/p/6686629174
https://tieba.baidu.com/p/6687216651
https://tieba.baidu.com/p/6687241276
https://tieba.baidu.com/p/6687266097
最近贴吧隐藏2017年之前的帖子,只有WAP版可见。
http://tieba.baidu.com/mo/m?kz=[帖子id]
问题出现在一个楼主连续占用了很多楼层、且图片极少的帖子之中。此前没有抓取过有这种特征的帖子,所以没有发现这个问题。
生成的html文件将许多楼层的正文被合并到了一起,原本该楼层的日期、层主ID、楼层号等基本格式被省略掉了。而且有的楼层的开头(比如图1里有张插图后面的“预计”2字,还有以序号“1、”“2、”开头的文字)被排到了上一层正文的末尾。这些使得页面看起来就比较凌乱。
详细可见部分截图以及原始网页的截图。原帖地址为这个。
感谢制作,好贴存在本地以免被封没得看了,在存某一贴时会卡在缓存两个gif上面,链接已经失效,报错HTTP ERROR 503,进而无法继续进行,可以考虑设置多少次失败就跳过,或者其他更妙的解决办法,感谢
原贴:
https://tieba.baidu.com/p/2103445499
exe报错:
2023-02-06 09:47:40 [Fetch] error fetching http://www.klss.cn/upimg/allimg/110221/105G34Z0-2.gif, pause for 3s: Get "http://www.klss.cn/upimg/allimg/110221/105G34Z0-2.gif": dial tcp: lookup www.klss.cn: no such host
2023-02-06 09:47:40 [Fetch] error fetching http://www.klss.cn/upimg/allimg/110221/105G34962-27.gif, pause for 3s: Get "http://www.klss.cn/upimg/allimg/110221/105G34962-27.gif": dial tcp: lookup www.klss.cn: no such host
当帖子标题里包含“:”、“|”这种不能作为文件名的符号的时候抓取网页将不会生成html和json文件。请问能否设置在遇到这种情形的时候在文件名里舍去这类符号,或者替换成符合要求的符号呢?
现在,这个工具爬取到的图片链接都是缩略图链接。爬取得到的网页,打开之后显示的自然也是缩略图链接。
而且还无法自动查看大图,原帖子里点击缩略图是可以查看大图的。
我想,反正用这个工具的人都是用电脑和宽带,没人会在乎流量吧。所以不如直接把图片链接替换成原图。
我找了几个帖子里面的图片,发现图片链接的命名挺好改的:
缩略图链接(这些链接似乎要手动复制粘贴到输入网址的地方才能打开,当然,在爬取得到的html文件里都是能正常显示的):
https://imgsa.baidu.com/forum/w%3D580/sign=b13fff0d831001e94e3c1407880c7b06/917edd628535e5ddf5e2133b78c6a7efcc1b6240.jpg
https://imgsa.baidu.com/forum/w%3D580/sign=93928a239e529822053339cbe7cb7b3b/b5dc04338744ebf8cffdd2dbd7f9d72a6259a787.jpg
https://imgsa.baidu.com/forum/w%3D580/sign=ffabff668e0a19d8cb03840d03fb82c9/aa482ec79f3df8dce2142946c311728b46102847.jpg
https://imgsa.baidu.com/forum/w%3D580/sign=f74848d9e724b899de3c79305e071d59/7a6b1dfa513d2697869e6a845bfbb2fb4216d826.jpg
大图链接:
https://imgsrc.baidu.com/forum/pic/item/917edd628535e5ddf5e2133b78c6a7efcc1b6240.jpg
https://imgsrc.baidu.com/forum/pic/item/b5dc04338744ebf8cffdd2dbd7f9d72a6259a787.jpg
https://imgsrc.baidu.com/forum/pic/item/aa482ec79f3df8dce2142946c311728b46102847.jpg
http://imgsrc.baidu.com/forum/pic/item/7a6b1dfa513d2697869e6a845bfbb2fb4216d826.jpg
我不懂程序,感觉只要在爬取完毕后进行全部替换:
https://imgsa.baidu.com/forum/.{1,45}
http://imgsrc.baidu.com/forum/pic/item
就能实现这个功能。
贴吧的表情的链接是这样的,不会被上面的替换影响到,所以应该不会有问题。
https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon13.png
当然这个也可以我自己手动做,下载下来之后用文本编辑器打开html全部替换就行了。
我是因为贴吧把以前的贴隐藏了才认识到必须得把重要帖子保存起来,然后搜了一圈就只发现了您这个最合适,能爬取一个帖子的所有内容(含所有楼中楼、图片),而且还能以html的形式保存下来!
所以对我来说,真正影响使用的是前面说的无法获得帖子最后一页的楼中楼,如果您看到这issue能不能说一下关于这点改起来是麻烦还是简单呢,如果不算麻烦的话希望能修改,现在我是日日盼夜夜盼😂
我不懂编程,所以如果掏钱能让您愿意把这点改进的话也好啊,我愿意赞助一些(50您看行不= =),谢谢了🙏
只看了33楼,反复测试几次都是如此
https://tieba.baidu.com/p/5381698176
发现都是这样。
https://tieba.baidu.com/p/3922635509 也是。
3楼爬取的内容,本应是“今晚在重新更吧竟然被删帖了”,结果有三个3楼,中间的一个是正确的,剩余的两个是大量的“希望各位吧友能支持魔吧月刊。”,大概是别的楼层的吧。
这是当时的日志
`[root@localhost tiebaSpider]# go run main.go
#
command-line-arguments
./main.go:72:19: undefined: fetchHTMLList
./main.go:73:22: undefined: parseHTML
./main.go:74:25: undefined: renderHTML
./main.go:87:16: select case must be receive, send or assign recv
./main.go:94:16: select case must be receive, send or assign recv
./main.go:101:16: select case must be receive, send or assign recv
./main.go:108:17: select case must be receive, send or assign recv
`
检查 JSON 文件会发现一部分楼层的时间变成了 "Time": "来自Android客户端"
看代码好像 这里 是解析楼层时间的?我比较建议直接整段拿到手然后正则 \d{4}-\d\d-\d\d \d\d:\d\d
提取,不要搞选择器精确选择了,各种边缘情况比较多,很容易出 BUG
有解决办法吗
首先还是感谢您能发布这么好的东西。试了几个帖子。
1、如果贴吧id后面有带表情符号的话,会乱码。例如这个帖子,
https://tieba.baidu.com/p/6209031748?pn=3
77楼的ID是“你失散的野爹😂”,用这个软件保存的结果是“钃濋瓟铦庰煢”
2、在楼中楼里的“A回复B:……”中,B有链接。但是打开这个链接会显示错误。
感觉不如直接把这个链接删了。
Hi,
我使用你的代码,成功保存了一批珍贵资料。感谢你所做的工作。
关于“收集网页出现的所有图片并保存至本地,把所有图片内嵌至html”,我的解决思路是这样的:
先使用tiebaImageGet将帖子图片下载到本地文件夹(名称为帖子PID),然后修改html文件中的image src. 这种方式下载的图片为贴吧缩略图,避免了浏览器同时加载原图导致内存占用过大的问题。
python代码如下:
def modify_src(folder_path, file_name):
file_path = folder_path + '//' + file_name
soup = BeautifulSoup(open(file_path, encoding = "utf-8"), "html.parser")
url = [elm.get_text() for elm in soup.find_all("a", href=re.compile(r"^https://tieba.baidu.com/p/"))]
# Some links are http
if len(url) == 0:
url_new = [elm.get_text() for elm in soup.find_all("a", href=re.compile(r"^http://tieba.baidu.com/p/"))]
pid = url_new[0][-10:]
else:
# get pid
pid = url[0][-10:]
# modify image src
# unmodified src: https://imgsa.baidu.com/forum/w%3D580/sign=4d3033fbbdde9c82a665f9875c8080d2/4417d558ccbf6c815f62fb2ab23eb13532fa4035.jpg
# modified: ./img/6233150605/09d6a94bd11373f0a6c6bb5daa0f4bfbf9ed0488.jpg
# pattern: ./img/pid/img_name
# img_name: img["src"][-44:]
# unmodified emoticon src :https://gsp0.baidu.com/5aAHeD3nKhI2p27j8IqW0jdnxx1xbK/tb/editor/images/client/image_emoticon72.png
# modified: ../emoticon/image_emoticon72.png
for img in soup.findAll('img',{"src":True}):
if img["src"].endswith(".jpg"):
modified = './img/' + pid + '/' + img['src'][-44:]
img['src'] = modified
if img['src'].endswith('.png'):
splited = img['src'].split('/')
emoticon_name = splited[-1]
emoti_modified = '../tieba_emoticon/' + emoticon_name
img['src'] = emoti_modified
with open(file_path, "w", encoding = "utf-8") as file:
file.write(str(soup))
所用到的emoticon文件:tieba_emoticon.zip
祝好,
Jingyi
https://tieba.baidu.com/p/6190643216
试了好几次,把这个url保存到txt里爬不到任何东西,其它帖子url放在txt里就没问题
以后要是有使用问题的话我是再开一个issue还是在这个帖子里回复呀😂
Hi,
感谢你分享这个出色的备份程序。
我在备份帖子时,遇到了这个报错信息:
[Parse] error: unable to parse page(title: 百度安全验证), possibly a network error, readding url to queue
我在浏览器中打开百度贴吧,完成了安全验证,然后重新执行程序。依然出现该报错信息。我尝试了退出百度账号/使用IP代理,无效。请问这个问题该如何解决?
环境:win10, go1.14.1, program runs in CMD.
go run main.go
输出如下
.\main.go:72:19: undefined: fetchHTMLList
.\main.go:73:22: undefined: parseHTML
.\main.go:74:25: undefined: renderHTML
.\main.go:87:16: select case must be receive, send or assign recv
.\main.go:94:16: select case must be receive, send or assign recv
.\main.go:101:16: select case must be receive, send or assign recv
.\main.go:108:17: select case must be receive, send or assign recv
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.