Code Monkey home page Code Monkey logo

baiduspider / baiduspider Goto Github PK

View Code? Open in Web Editor NEW
962.0 962.0 214.0 45.59 MB

BaiduSpider,一个爬取百度搜索结果的爬虫,目前支持百度网页搜索,百度图片搜索,百度知道搜索,百度视频搜索,百度资讯搜索,百度文库搜索,百度经验搜索和百度百科搜索。

Home Page: https://baiduspider.github.io

License: GNU General Public License v3.0

Python 99.78% Shell 0.22%
baidu baiduspider crawler python python-crawler search spider

baiduspider's Introduction

Contributors Forks Stargazers Issues MIT License


Logo

BaiduSpider

一个爬取百度的利器
简体中文 | 繁體中文 | English
快速上手 »

查看示例 · 报告问题 · 请求需求

目录
  1. 关于本项目
  2. 起步
  3. 简单使用
  4. 项目路线图
  5. 项目共建
  6. 开源协议
  7. 联系方式
  8. 免责声明
  9. 贡献者
  10. 致谢

关于本项目

项目截图

搜索引擎是一个十分强大的工具,如果能让其他工具集成搜索引擎的众多强大功能,那么这些工具必将变得更加强大。但目前我没有找到一个可以精准提取搜索引擎搜索结果的开源爬虫。于是,我便编写了这个爬取百度搜索引擎的项目:BaiduSpider。

BaiduSpider 的独特功能:

  • 节省提取数据的时间,对于类似深度学习项目的数据模型建立与训练起到了良好的帮助。

  • 精准提取数据,并删除广告。

  • 搜索结果大而全,支持多种搜索类型,支持多种返回类型。

当然,没有一个项目是完美的。任何一个项目的发展都需要社区的帮助。你可以通过发布 Issue 或提交 PR 来帮助 BaiduSpider 进步!:smile:

一些比较有帮助的文档或工具将在最后的致谢部分中列出。

依赖库

一些 BaiduSpider 使用的主要开源依赖库。

起步

为了安装 BaiduSpider,请按照以下几个步骤操作。

预先条件

在安装 BaiduSpider 之前,请确保你安装了Python3.6+

$ python --version

若版本小于3.6.0,请到Python官网下载并安装 Python。

安装

使用pip安装

请在命令行中键入:

$ pip install baiduspider

从 GitHub 手动安装

$ git clone [email protected]:BaiduSpider/BaiduSpider.git

# ...

$ python setup.py install

简单使用

你可以使用以下代码,通过 BaiduSpider 获取百度的网页搜索结果:

# 导入BaiduSpider
from baiduspider import BaiduSpider
from pprint import pprint

# 实例化BaiduSpider
spider = BaiduSpider()

# 搜索网页
pprint(spider.search_web(query='Python'))

更多样例和配置,请参照文档

项目路线图

请参考 Opening Issues 以获取最新的项目规划以及已知问题。

项目共建

社区的贡献是开源项目的灵魂所在,也是整个开源社区学习、交流、获得灵感的方式。我们极力欢迎任何人参与本项目的开发与维护。

具体参与步骤如下:

  1. Fork 此项目
  2. 创建 Feature 分支 (git checkout -b NewFeatures)
  3. 在每次修改代码后,提交你的更改 (git commit -m 'Add some AmazingFeature')
  4. 将更改推送到自己的远程仓库 (git push origin username/BaiduSpider)
  5. 在 GitHub 上打开你的仓库,根据指引提交 PR

开源协议

本项目基于GPL-V3开源,详情请参见LICENSE

联系方式

samzhangjy - @samzhangjy - [email protected]

项目链接:https://github.com/BaiduSpider/BaiduSpider

免责声明

此项目仅作为学习用途,不可商用或用于爬取百度大量数据。此外,本项目使用GPL-V3版权协议,意味着涉及(使用)此项目的任何其它项目必须开源且注明出处,并且本项目作者不承担滥用导致的任何法律风险。特此说明,违者后果自负。

贡献者

致谢

baiduspider's People

Contributors

dependabot[bot] avatar fhu-yezi avatar glacierck avatar goldensoap avatar samzhangjy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

baiduspider's Issues

[BUG]install error

描述该问题
python setup.py install
.. ...
Installed d:\dev\python\lib\site-packages\baiduspider-0.0.6-py3.8.egg
Processing dependencies for BaiduSpider==0.0.6
Searching for htmlmin
Reading https://pypi.org/simple/htmlmin/
Download error on https://pypi.org/simple/htmlmin/: [Errno 2] No such file or directory -- Some packages may not be found!
Couldn't find index page for 'htmlmin' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: [Errno 2] No such file or directory -- Some packages may not be found!
No local packages or working download links found for htmlmin
error: Could not find suitable distribution for Requirement.parse('htmlmin')

复现该问题
python 3.8.7
python setup.py install

请提供能够复现该问题的代码或步骤。
windows 10 + python 3.8.7
python setup.py install

预期结果

安装成功

实际结果

安装错误

系统

  • Windows 10 Pro 1909
  • Python版本: 例如:3.8.7

其他描述

一些关于问题的其他的描述。

[BUG] Basic `BaiduSpider()` does not work.

描述该问题

Basic BaiduSpider() does not work. (Is it blocked by Baidu? The same code had worked perfectly fine.)

复现该问题

~ python
Python 3.9.4 (default, Apr  5 2021, 01:49:30)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from baiduspider import BaiduSpider
>>> spider = BaiduSpider()
>>> spider.search_news(query="Hello", pn=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/baiduspider/__init__.py", line 499, in search_news
    self._handle_error(error)
  File "/usr/local/lib/python3.9/site-packages/baiduspider/_spider.py", line 68, in _handle_error
    raise err
  File "/usr/local/lib/python3.9/site-packages/baiduspider/__init__.py", line 493, in search_news
    result = self.parser.parse_news(code)
  File "/usr/local/lib/python3.9/site-packages/baiduspider/parser/__init__.py", line 461, in parse_news
    res.find("div", class_="c-span-last")
AttributeError: 'NoneType' object has no attribute 'find'
>>>

Similar for IPython

~ export DEBUG=1
➜  ~ ipython
Python 3.9.4 (default, Apr  5 2021, 01:49:30)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.23.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from baiduspider import BaiduSpider

In [2]: spider = BaiduSpider()

In [3]: results = spider.search_news(query="Hello", pn=0)['results']
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-4d3b276d2fa8> in <module>
----> 1 results = spider.search_news(query="Hello", pn=0)['results']

/usr/local/lib/python3.9/site-packages/baiduspider/__init__.py in search_news(self, query, pn)
    497         finally:
    498             if error:
--> 499                 self._handle_error(error)
    500         return {"results": result["results"], "total": result["pages"]}
    501

/usr/local/lib/python3.9/site-packages/baiduspider/_spider.py in _handle_error(self, err, parent, cause)
     66             return None
     67         if bool(int(os.environ.get("DEBUG", 0))):
---> 68             raise err
     69         else:
     70             print(

/usr/local/lib/python3.9/site-packages/baiduspider/__init__.py in search_news(self, query, pn)
    491             # 压缩
    492             code = self._minify(source.text)
--> 493             result = self.parser.parse_news(code)
    494             result = result if result is not None else self.EMPTY
    495         except Exception as err:

/usr/local/lib/python3.9/site-packages/baiduspider/parser/__init__.py in parse_news(self, content)
    459             # 作者
    460             author = (
--> 461                 res.find("div", class_="c-span-last")
    462                 .find("div", class_="news-source")
    463                 .find("span", class_="c-gap-right")

AttributeError: 'NoneType' object has no attribute 'find'

预期结果

spider.search_news(query="Hello", pn=0) should return normally.

实际结果

Error

系统

  • macOS Catalina, 10.15.7
  • Python 3.9.4
  • baiduspider build on May 27
➜  baiduspider ll
total 72
drwxr-xr-x    8 muchong  admin    256 May 27 09:28 ./
drwxr-xr-x  193 muchong  admin   6176 Jun 17 11:37 ../
-rw-r--r--    1 muchong  admin  26149 May 27 09:28 __init__.py
drwxr-xr-x    5 muchong  admin    160 May 27 09:28 __pycache__/
-rw-r--r--    1 muchong  admin   3252 May 27 09:28 _spider.py
drwxr-xr-x    4 muchong  admin    128 May 27 09:28 errors/
drwxr-xr-x    5 muchong  admin    160 May 27 09:28 parser/
-rw-r--r--    1 muchong  admin   1913 May 27 09:28 util.py
➜  baiduspider pwd
/usr/local/lib/python3.9/site-packages/baiduspider

其他描述

N/A

[BUG]search_video搜索汉字,比如‘傈僳’时,搜索结果内没有包含这两个字

pprint(spider.search_video(query=input('视频搜索关键词:')))

执行上述代码后,在命令行后输入‘傈僳’两个字时,查询出的结果内没有‘傈僳’这连个字。

image

我用的就是下面的代码:
`from baiduspider import BaiduSpider
from pprint import pprint

spider = BaiduSpider()

# 搜索视频
pprint(spider.search_video(query=input('视频搜索关键词:')))`

系统

  • 操作系统: Windows10 64位
  • Python版本: anaconda3 Python 3.7

[BUG]运行示例代码没有返回结果

python版本3.8.6

from pprint import pprint
from baiduspider import BaiduSpider

result = BaiduSpider().search_web("python",pn=1)
print(result)  # print
print('\n\n')
pprint(result)

返回值
image

[FEATURE] 不能抓取音乐卡片

描述该问题

不能抓取音乐卡片

复现该问题

请播放踏山河

预期结果

res_type=music

实际结果

none

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG] 运行示例代码报错

描述该问题

代码示例:

from baiduspider import BaiduSpider
from pprint import pprint
spider = BaiduSpider()
pprint(spider.search_web(query='Python'))

预期结果

返回搜索结果

实际结果

图片

系统

  • 操作系统: MacOS
  • Python版本: 3.8.5

[BUG]在搜索结果为空时, 报找不到"total"键

描述该问题

在#91中出现的问题,并没有得到真正修复 . [报错产生的原因在baiduspider->parser文件夹->init.py->Parser类->parse_web函数

#__init__.py文件31行32行
  if soup.find("div", id="content_left") is None:
     return {"results": [], "pages": 0}

因为搜索结果为空返回的解析结果中不包含id为content_left的div . 所以这里会直接返回空集.
在上层调用(位于baiduspider->init.py 453行因为索引 total而报错)
pages = self._calc_pages(results["total"], self.RESULTS_PER_PAGE["web"])
复现该问题

通过代码或者百度网页 , 输入随便什么, 通过搜索工具限制时间, 达到无结果页面, 可以在F12 或 BS4 解析结果内看到没有相关div

系统

  • 操作系统: ubuntu20.04
  • Python版本: 例如:3.9
  • 库版本:1.0.1.3

[FEATURE]

你的功能请求是跟一个问题有关吗?请描述。
没有广告标识的信息
你的问题的清晰的描述。
如搜索关键字 旅游 在最上方的的几条带有广告字样的是检索不到的
你想要什么
是否能把用户看到的真实信息返回
对你想要的功能的尽量清晰的描述。
所见即所得
你想过的解决方案

简单描述一下你想用的解决方案。

其他描述

其他关于该功能请求的描述。

[BUG] 图片搜索时的tb

Exception has occurred: TypeError (note: full exception trace is shown but execution is paused at: _run_module_as_main)
_handle_error() missing 2 required positional arguments: 'parent' and 'cause'
File "/usr/local/python3.8/lib/python3.8/site-packages/baiduspider/init.py", line 297, in search_pic
self._handle_error(error)
File "/task/github/autoVedio/txtToImg/baidu.py", line 11, in StartParseTxtToImg
searchlist = spider.search_pic(text)
File "/task/github/autoVedio/main.py", line 24, in
StartParseTxtToImg("网上说抽烟不好","/imgdata/")
File "/usr/local/python3.8/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/python3.8/lib/python3.8/runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/local/python3.8/lib/python3.8/runpy.py", line 263, in run_path
return _run_module_code(code, init_globals, run_name,
File "/usr/local/python3.8/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/python3.8/lib/python3.8/runpy.py", line 193, in _run_module_as_main (Current frame)
return _run_code(code, main_globals, None,

[BUG] spider.search_news 失效

datas=spider.search_news(query=input('资讯搜索关键词:'))
print(datas)

output:
资讯搜索关键词:美国
WARNING: An error occurred while executing function ., which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable DEBUG to 1 to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D.
{'results': [], 'total': 0}

简单测试了一下:问题在
def search_news(self, query: str, pn: int = 1) -> dict:
result = self.parser.parse_news(code)

parse_news 格式化内容,没有提取到,最近百度有更新,建议修改一下提取

[BUG]百度搜索内容为空时程序报错

描述该问题

直接百度搜索返回结果为空时,程序运行报错。
复现该问题

from baiduspider import BaiduSpider
result = BaiduSpider().search_web('这格瓦拉还算有义气,收了钱肯办事儿。', exclude=["tieba", "baike"])
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/baiduspider/init.py", line 453, in search_web
pages = self._calc_pages(results["total"], self.RESULTS_PER_PAGE["web"])
KeyError: 'total'

预期结果

result = BaiduSpider().search_web('这格瓦拉还算有义气', exclude=["tieba", "baike"])
result.plain
[{'title': '窃·格瓦拉为什么说里面个个人才,说话又好听? - 哔哩哔哩', 'des': '还有300家机构,拿着真金白银要和窃格瓦拉签约。 进监狱前,窃格瓦拉说里面个个都是人才,说话又好听,超喜欢在里面。 为流行文化研究带师,我们不可能不对监狱文化有所涉猎。那么监狱里...', 'origin': '哔哩哔哩', 'url': 'http://www.baidu.com/link?url=dN6rXnP5kpBABzs8UQYKwMuXWQvAUWN2pvf24vlm9YXudhnK8PdnICn2QoxuW9UWy7fyTs7GLlJKStUZIq3DAK', 'time': '2020年4月22日', 'type': 'result'}, {'title': '切·格瓦拉真值得一些人如此崇拜吗? - 知乎', 'des': '他够义气:他仅凭一腔热血和对卡斯特罗革命的认同,就能奋不顾身参加未知战斗;他与挚友卡米洛西恩福格斯...', 'origin': '知乎', 'url': 'http://www.baidu.com/link?url=Cjfv9VL1wGG_Zb0JYaSkU1PqouzeKpAjrYnseXB-Tu3kWGbhtQ8d_IgB00TfkbPQRib05DhSpJrAWRAoeRw8QExDs-T6qcnG62rDLMMKDpy', 'time': '2016年11月29日', 'type': 'result'}, {'title': '精神领袖“窃·格瓦拉”首度公开道歉,这几句话令人深思!', 'des': '当年所谓的江湖精神,就是能为弟兄们做些讲“义气”的事,这也是融入这个圈子所必须遵从的生存理念。正如他在视频直播所说,现在只想在家种地,照顾好父母,也许这也是他为追求“自我的自...', 'origin': '弥涅耳瓦的猫头鹰', 'url': 'http://www.baidu.com/link?url=UqWCugy4ZBY5iz1EsCmWAnSl8LYQe0tB8BKPpk2U5ae6NKt07_7NYACs2ot8poGA-BYFNHMuOY5m6f_wEpaKbAn8YhZQIo9CLd36O07Jpgy', 'time': '2020年6月5日', 'type': 'result'}, {'title': '说实话我不太喜欢窃格瓦拉这人,感觉没什么人性 - 虎扑社区', 'des': '既然**主播这种都有人喜欢,觉得切格瓦拉说话有意思也没什么可喷的吧,至少切格瓦拉是说自己真实想法的...', 'origin': 'bbs.hupu.com/341681...html', 'url': 'http://www.baidu.com/link?url=cHK4cW-bHsmpF-YWJSAK2KOHdijK276rxvjkYyv0RU2Ev9xl15osQCxYxYTkCAB', 'time': '2020年4月12日', 'type': 'result'}, {'title': '为什么窃格瓦拉会那么受到崇拜?【历史吧】 - 百度贴吧', 'des': '为什么窃格瓦拉会那么..一方面,窃身上充满了理想的光辉,2012年接受采访之后继续偷电车,抓了放放了偷,从没有去打过工,用自己的名气赚钱,这就像切从来没有放弃理...', 'origin': '百度贴吧', 'url': 'http://www.baidu.com/link?url=TUqICG81hMifYA4O1KSUtBn5i_g2iEYuMkZYs-apsmYSUEIRlSdVZZvmXGnFm_NX', 'time': '2018年9月25日', 'type': 'result'}, {'title': '如何评价窃·格瓦拉? - 哔哩哔哩', 'des': '窃·格瓦拉,原名周立齐,绰号“阿三”,男,1984年12月27日出生于广西壮族自治区南宁市,壮族,小学文化,无业,户籍所在地南宁市兴宁区。 入刑记录 于2007年6月4日因...', 'origin': '哔哩哔哩', 'url': 'http://www.baidu.com/link?url=6s7_NW3BzrUBdq7a1xuIAXA4OBihIakbyhN6X9rQgERRB3ZWFwHQBDLmmLNgUsgqOhrDo6Eoe-GjoINYve1sxK', 'time': '2020年4月12日', 'type': 'result'}, {'title': '重新做人的“窃格瓦拉”,为什么不能当网红?', 'des': '窃格瓦拉也是媒体的“宠儿”。早在三月底四月初,就有众多自媒体报道“窃格瓦拉即将出狱”,像是为其“归来”造势一样。4月18日当天,有关他的报道铺天盖般出现在各大互联网平台,“这辈...', 'origin': '暮雨潇潇dfhdkf', 'url': 'http://www.baidu.com/link?url=EE1w9he2-rX_Ii1s7DOTMLZAvzyQnGV_1ur-zYsygU6yFS-M10IIspX7bw1h-H5ZeIjj_rCLaggcEzCDufnlFM8d0byY1cntBtNcNc-cFaa', 'time': '2020年4月24日', 'type': 'result'}, {'title': '切·格瓦拉真值得一些人如此崇拜吗 - 百度知道', 'des': '最佳答案: 他够义气:他仅凭一腔热血和对卡斯特罗革命的认同,就能奋不顾身参加未知战斗;他与挚友卡米洛西恩福格斯情同手足,甚至将自己儿子的取名卡米罗以缅怀逝去的朋友;...更多关于这格瓦拉还算有义气的问题>>', 'origin': '百度知道', 'url': 'http://www.baidu.com/link?url=d_esFLv8lv-8TBe1wY1lzPbaHMwnj2CkPb0Em_SUviWfeCRSjtf_X-Xp9kOH0Z19Dibq1KEZBzaWhXff_gwSEuEoK3-j1kqGkXJVWYmPdka', 'time': None, 'type': 'result'}, {'title': '如何评价切·格瓦拉与卡斯特罗? - 知乎', 'des': '在墨西哥城,卡斯特罗遇到了切·格瓦拉。他们二人一见如故,结下了深厚的革命友谊,对卡斯特罗来说,切既...', 'origin': '知乎', 'url': 'http://www.baidu.com/link?url=b9yoYMmJ3n0Vn11SNEl9XETa4VcMoKsFlRTZ3JCu7Y2F4whpDH2zMiOMgO5eEc_FlujXnKQGMUdpoxLKYfNqZ', 'time': '2016年11月25日', 'type': 'result'}, {'title': '为什么我们想“躺平”?|窃·格瓦拉|切·格瓦拉', 'des': '家境贫苦,小时候经常光脚上学,而接受正规教育止于小学,曾北上打过工,也谈过一个漂亮的女朋友。在年近五旬的大姐眼里,窃·格瓦拉对朋友讲义气,人也善良,“那时年...', 'origin': '腾讯网', 'url': 'http://www.baidu.com/link?url=cUYtNmwMzSKkZWLR1xIVxjLgALvWTBDQOJ82JMrp8lzrJtmJzW3l-e2m7sp33TwUve8bg6IMYODFWPm4OUNR2a', 'time': '2021年6月1日', 'type': 'result'}]
image

实际结果

result = BaiduSpider().search_web('这格瓦拉还算有义气,收了钱肯办事儿。', exclude=["tieba", "baike"])
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/baiduspider/init.py", line 453, in search_web
pages = self._calc_pages(results["total"], self.RESULTS_PER_PAGE["web"])
KeyError: 'total'
image

系统

  • 操作系统: MacOS
  • Python版本: 3.8
  • 版本:BaiduSpider 1.0.1.2

其他描述

百度网页搜索返回空的时候,程序搜索为空。

[BUG] baiduspider.errors.ParseError: Invalid control character at: line 1 column 60799 (char 60798)

my code:

from baiduspider import BaiduSpider
from pprint import pprint

if __name__ == "__main__":
    keyword = '道路破损'
    max_page = 100

    spider = BaiduSpider()
    for pn in range(max_page):
        pprint(spider.search_pic(keyword, pn))

after about 30 iter, I get:

Traceback (most recent call last):
  File ".\spider_data.py", line 11, in <module>
    pprint(spider.search_pic(keyword, pn))
  File "C:\Users\\Miniconda3\envs\pytorch\lib\site-packages\baiduspider\__init__.py", line 232, in search_pic
    self._handle_error(error)
  File "C:\Users\\Miniconda3\envs\pytorch\lib\site-packages\baiduspider\_spider.py", line 71, in _handle_error
    raise error
  File "C:\Users\\Miniconda3\envs\pytorch\lib\site-packages\baiduspider\__init__.py", line 228, in search_pic
    result = self.parser.parse_pic(content)
  File "C:\Users\\Miniconda3\envs\pytorch\lib\site-packages\baiduspider\parser.py", line 288, in parse_pic
    if error: raise ParseError(str(error))
baiduspider.errors.ParseError: Invalid control character at: line 1 column 60799 (char 60798)

System:

OS : Windows 10
python : 3.6.10

How can I fix this problem?

[BUG]ParseError: Invalid HTML content.

描述该问题

一个对该问题的清晰的描述。
搜索'异度侵入'时报 ParseError: Invalid HTML content.

复现该问题

请提供能够复现该问题的代码或步骤。
t = BaiduSpider()
a = t.search_web(query='异度侵入', pn=1)

预期结果

一个对你想要的结果的清晰的描述。
搜素异度侵入的结果

实际结果

你实际得到的结果。

import requests...

ParseError Traceback (most recent call last)
e:\github\Aggregate-search\AgSearch\baidu.py in
81 if name == 'main':
82 t = BaiduSpider()
---> 83 a = t.search_web(query='异度侵入', pn=1)
84

~\AppData\Local\Programs\Python\Python38\lib\site-packages\baiduspider_init_.py in search_web(self, query, pn)
180 error = err
181 finally:
--> 182 self._handle_error(error)
183 return {
184 'results': results['results'],

~\AppData\Local\Programs\Python\Python38\lib\site-packages\baiduspider_spider.py in _handle_error(self, err)
69 else:
70 error = UnknownError(str(err))
---> 71 raise error
72
73 def repr(self) -> str:

~\AppData\Local\Programs\Python\Python38\lib\site-packages\baiduspider_init_.py in search_web(self, query, pn)
176 url = 'https://www.baidu.com/s?wd=%s&pn=%d' % (text, (pn - 1) * 10)
177 content = self._get_response(url)
--> 178 results = self.parser.parse_web(content)
179 except Exception as err:
180 error = err

~\AppData\Local\Programs\Python\Python38\lib\site-packages\baiduspider\parser.py in parse_web(self, content)
23 soup = BeautifulSoup(content, 'html.parser')
24 if soup.find('div', id='content_left') is None:
---> 25 raise ParseError('Invalid HTML content.')
26 # 获取搜索结果总数
27 num = int(str(soup.find('span', class_='nums_text').text).strip(

ParseError: Invalid HTML content.

系统

  • 操作系统: Win10x64例如:MacOS
  • Python版本:3.8.2 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG]

描述该问题

在多次请求(多线程)的情况下会出现
WARNING: An error occurred while parsing the tieba subcomponent of BaiduSpider.parse_web, which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider.

复现该问题

`

-- coding: utf-8 --

from baiduspider import BaiduSpider
import threading
import queue
import xlsxwriter

class MyThread(threading.Thread):
def init(self, page):
super().init()
self.page = page

def run(self) -> None:
    while True:
        if self.page.empty():
            break
        self.get_info()

def get_info(self):
    page = self.page.get()
    spider = BaiduSpider()
    response = spider.search_web(query="欧阳靖", pn=page)
    data = []
    for result in response["results"]:
        url = result.get("url")
        if result.get("url"):
            data.append(result.get("url"))
            continue
        result_type = result.get("type")
        # 百科处理
        if result.get("result") and result_type != 'total':
            data.append(result.get("result").get("url"))
            continue
        # 其他处理
        if result_type != 'total' and result_type != "related":
            for i in result.get("results"):
                data.append(i.get('url'))
    if len(excel_data) % 1000 == 0:
        excel_data.append([])
    excel_data.append(data)
    print(page)

excel_data = []

启动线程队列

work_queue = queue.Queue()

传参

for i in range(1, 300):
work_queue.put(i)

threads = []
for j in range(50):
thread_do = MyThread(work_queue)
thread_do.start()
threads.append(thread_do)

for k in threads:
k.join()

def to_excel():
column = ['链接'] # 列表对应每列的列名
test = pd.DataFrame(columns=column, data=self.data)
path = r'./1.xlsx'
test.to_excel(path, engine='xlsxwriter') # 如果生成excel,可以用to_excel
`

实际结果

起码不报错吧, 也不知道是什么

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

[BUG] linux Python3.6.9 使用spider.search_wenku('key') 报错: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/dbachen/BaiduSpider/baiduspider/__init__.py", line 585, in search_wenku pages_ = bs.find('div', class_='page-content').findAll('a') AttributeError: 'NoneType' object has no attribute 'findAll'

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

报错信息: WARNING: An error occurred while parsing the news subcomponent of BaiduSpider.parse_web, which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable `DEBUG` to `1` to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D. WARNING: An error occurred while parsing the aike subcomponent of BaiduSpider.parse_web, which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable `DEBUG` to `1` to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D.

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG]search_news返回结果为空

描述该问题

search_news返回结果为空

复现该问题

from baiduspider import BaiduSpider
from pprint import pprint
spider = BaiduSpider()
pprint(spider.search_news(query='python'))

实际结果

WARNING: An error occurred while executing function ., which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable DEBUG to 1 to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D.
{'results': [], 'total': 0}

系统

  • 操作系统: Windows
  • Python版本: 3.7

其他描述

  1. 换其他关键词尝试,total的结果可能不为0,但results结果仍然为空
  2. serach_web返回结果不为空,与主页示例代码一致,但是仍然有如下warning:
    WARNING: An error occurred while parsing the aike subcomponent of BaiduSpider.parse_web, which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable DEBUG to 1 to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D.

[BUG]文库搜索不了

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

1

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG]search_web页面出现贴吧信息时parse_web错误

描述该问题

搜索『石家庄』、『中海油』等关键字时,如果有贴吧信息则无法解析页面内容。

复现该问题

from baiduspider import BaiduSpider
from pprint import pprint

results = self.search_web('石家庄', 1)['results']

预期结果

1、增加对贴吧信息的支持
2、在baiduspider/parser.py 约第200行位置,增加对『result』变量是否存在『tpl』属性的先决判断。

实际结果

ERROR log 228 Internal Server Error: /crawling/
Traceback (most recent call last):
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/rest_framework/views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "/Users/admin/Downloads/python_projects/work_project/rosefinch/rosefinch/utils/jwt_auth.py", line 234, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
    raise exc
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/admin/Downloads/python_projects/work_project/rosefinch/rosefinch/apps/crawling/views.py", line 26, in post
    res = Baidu().my_search_web(request.data['keyword'], request.data['page'])
  File "/Users/admin/Downloads/python_projects/work_project/rosefinch/rosefinch/apps/crawling/web_sites/baidu/baidu.py", line 7, in my_search_web
    results = self.search_web(query, pn)['results']
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/baiduspider/__init__.py", line 182, in search_web
    self._handle_error(error)
  File "/anaconda3/envs/rosefinch/lib/python3.6/site-packages/baiduspider/_spider.py", line 71, in _handle_error
    raise error
baiduspider.errors.UnknownError: 'tpl'

系统

  • 操作系统: MacOS 10.13.3
  • Python版本: Python 3.6.8 :: Anaconda, Inc.
  • BaiduSpider: 0.0.3

其他描述

无。

循环抓取时报错及中文报错

问题一:循环抓取

for page in range(2,21): try: pprint(spider.search_zhidao(query=query,pn=page)) except Exception as Error: print(Error)

错误如下

WARNING: An error occurred while executing function ., which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable DEBUGto1to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D. Traceback (most recent call last): File "D:/Project/upstar/SpiderBaidu.py", line 11, in <module> pprint(spider.search_zhidao(query=query,pn=page)) File "D:\Progarming\PythonEnvs\upstar-e7ASbuYY\lib\site-packages\baiduspider\__init__.py", line 386, in search_zhidao return {"results": result["results"], "total": result["pages"]} UnboundLocalError: local variable 'result' referenced before assignment
加入Try可以解决这个问题。但不能解决根源问题。

问题二、使用中文时报错,需要将中文转为uincode才可以使用

`
pprint(spider.search_zhidao(query=u‘游戏’))

pprint(spider.search_zhidao(query='\u6e38\u620f'))
`

[BUG]

描述该问题

调用search_web添加屏蔽搜索结果前后result数量没有区别,type还是显示为'total'

复现该问题

exclude = ['news', 'video', 'baike', 'tieba', 'blog', 'gitee', 'related', 'calc']
spider.search_web(query='**银行', time=(datetime(2011, 1, 1), datetime(2012, 1, 1)), exclude=exclude) #结果为48600000
spider.search_web(query='**银行', time=(datetime(2011, 1, 1), datetime(2012, 1, 1))) #result数量相同

系统

  • 操作系统: MacOS
  • Python版本: 3.8

[BUG]连续多次搜索后报错KeyError: 'total'

描述该问题

连续多次搜索后报错KeyError: 'total'

复现该问题

from baiduspider import BaiduSpider
result = BaiduSpider().search_web('Python', exclude=["tieba", "baike"])

预期结果

from baiduspider import BaiduSpider
result = BaiduSpider().search_web('Python', exclude=["tieba", "baike"])
result.plain
[{'title': 'Welcome to Python.org', 'des': 'The official home of the Python Programming Language', 'origin': 'www.python.org/', 'url': 'http://www.baidu.com/link?url=GDThJSZas_pwwrf4DrH3KFh_YoHaoqTNX6qoBGk9Ged0WKYVo_jULTxPYWCxs6n9', 'time': None, 'type': 'result'}, {'title': '下载和安装 python - Download Python | Python.org', 'des': 'The official home of the Python Programming Language', 'origin': 'www.python.org/getit/', 'url': 'http://www.baidu.com/link?url=2j7ljbFGKNKnXNMdsEqyKywXoroZfMtWWI-YeI-bZjs5z0tifD3hR9dqfagRfceW', 'time': '2021年10月4日', 'type': 'result'}, {'title': 'Python 基础教程 | 菜鸟教程', 'des': '/usr/bin/python的解释,相信很多不熟悉 Linux 系统的同学需要普及这个知识,脚本语言的第一行,只对 Linux/Unix 用户适用,用来指定本脚本用什么解释器来执行。 有这句的,加上执行权限后...', 'origin': 'www.runoob.com/python/python-t...', 'url': 'http://www.baidu.com/link?url=qnW2ykMn2V5BLlkwDGeeoLKIY94ritYVSJvrQBepTSrzGC-o3zmT-RGYtZ03V-ImbLullpPOdJVS5FWCvuZ6qa', 'time': '2020年1月1日', 'type': 'result'}, {'title': 'Python教程 - 廖雪峰的官方网站', 'des': '中文,免费,零起点,完整示例,基于最新的Python 3版本。 Python是一种计算机程序设计语言。你可能已经听说过很多种流行的编程语言,比如非常难学的C语言,非常流行的Java语言,适合初学者的Basic语言,...', 'origin': 'www.liaoxuefeng.com/wiki/10169...', 'url': 'http://www.baidu.com/link?url=0EA9kRmbscstDMVQcHCZCabi4cvske-gXfadYjhO2sEDuxueHEBEmuGw5HZn0-zC_bXOP8qE9vvzhwqxUhytU_', 'time': None, 'type': 'result'}, {'title': '你都用 Python 来做什么? - 知乎', 'des': '发现很多人都在学习 Python ,但是没有明确的说明可以做什么,主流的功能是什么?想知道目前利用 Python 开发的都在干什么? 关注者38,147 被浏览11,484,439 关注问题\u200b写回答 \u200b邀请回...', 'origin': '知乎', 'url': 'http://www.baidu.com/link?url=oKOE6ayTgW-BSh4iUlZnkcwTs_WgoZm8ON-AlN1onNg5pvpwrWyXRPTMP9qKWr1I5_ai1Uxp11eXq8CSq4YRBK', 'time': '2019年10月17日', 'type': 'result'}]

实际结果

from baiduspider import BaiduSpider
result = BaiduSpider().search_web('Python', exclude=["tieba", "baike"])
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/baiduspider/init.py", line 453, in search_web
pages = self._calc_pages(results["total"], self.RESULTS_PER_PAGE["web"])
KeyError: 'total'

系统

  • 操作系统: Ubuntu
  • Python版本: Python 3.8.0
  • BaiduSpider 版本: 1.0.1.1

其他描述

连续多次调用正常后开始一直报错。

[V1.0.0] BaiduSpider V1.0.0 发布!

新功能:

  • 💥 全面的类型注释支持,更好的开发体验
  • 💥 重写大部分核心解析代码,以适应最新的百度界面
  • 💥 Issue #7 移动端搜索支持(仅限网页搜索基本支持)
  • 💥 使用Cookie来延缓百度的封禁(仅限网页搜索)
  • ✨ Issue #26 音乐块抓取
  • ✨ 视频搜索爬取站点更改为https://www.baidu.com/sf/vsearch,更全面的搜索结果
  • ✨ 资讯搜索添加两个高级搜索功能:排序和筛选
  • ✨ 知道搜索添加一个高级搜索功能:按时间筛选
  • ✨ 文库搜索添加众多筛选与排序功能,并增加搜索结果类别
  • ✨ 经验搜索添加一个高级搜索功能:筛选
  • ✨ 添加代理设置参数
  • ✨ 使用搜索结果总数反推出搜索结果总页数(由@qwertylx提出)
  • ✔️ 更加模块化的代码
  • 📝 更详尽的文档
  • 🎨 全新图标

感谢洛谷大神@Mine_King提供的设计方案

2021.8.4 BaiduSpider v1.0 正式发布!

[BUG]百度人机验证码

root@i ~]# curl https://www.baidu.com/s?ie=utf8&oe=utf8&wd=curl [1] 14570 [2] 14571 [root@i ~]# <a href="https://wappass.baidu.com/static/captcha/tuxing.html?&amp;ak=c27bbc89afca0463650ac9bde68ebe06&amp;backurl=https%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf8&amp;logid=8871806922390316314&amp;signature=63c42cdf040b51fd402cb53e7db10eaf&amp;timestamp=1618224779">Found</a>.

过多爬取就这样了,旋转验证码

[FEATURE]我想要一个能判断 网址内页是否被百度收录的接口

你的功能请求是跟一个问题有关吗?请描述。

你想要什么

程序能提供一个http接口,参数为网址,程序来判断是否有被收录, 还有 需要防范百度的反爬

你想过的解决方案

flask 提供http服务,从ip代理池中获取到ip,代理 进行查询
其他描述

[BUG]UnboundLocalError: local variable 'results' referenced before assignment

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG]当我使用search_news不停地出现如下错误

描述该问题

我使用search_news不停地出现KeyError: 'total'的错误。可是需要爬取的单词可以在百度新闻处找到结果。也尝试了加cookie,在爬取五六个词之后很长一段时间都只报这个错误,我爬的数据非常少,每个词至多只爬20条数据,可是加上sleep都没有用。

复现该问题

File "", line 58, in spyder
baidu = BaiduSpider().search_news(i, show='media', pn=p)
File "=", line 787, in search_news
pages = self._calc_pages(result["total"], self.RESULTS_PER_PAGE["news"])
KeyError: 'total'

预期结果

希望知道为什么出现这样的错误,如何解决

系统

  • 操作系统: 例如:windows
  • Python版本: 例如:3.6

[BUG]AttributeError: 'NoneType' object has no attribute 'findAll'

描述该问题

使用新闻搜索爬取关键词,出现上诉情况

复现该问题

from baiduspider import BaiduSpider
from pprint import pprint

res = BaiduSpider().search_news('粤港澳大湾区')
count = res['total']
all=100;
page = 1;

预期结果

目标新闻res

实际结果

报错

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

WARNING: An error occurred while parsing the aike subcomponent of BaiduSpider.parse_web, which is currently ignored. However, the rest of the parsing process is still being executed normally. This is most likely an inner parse failure of BaiduSpider. For more details, please set the environment variable `DEBUG` to `1` to see the error trace and open up a new issue at https://github.com/BaiduSpider/BaiduSpider/issues/new?assignees=&labels=bug%2C+help+wanted&template=bug_report.md&title=%5BBUG%5D.[BUG]

开始爬web,zhidao接口都可以,但是爬一阵子之后就报这bug,返回为空list,满屏都是重复抛这个bug

在查询百度百科时,如果查不到结果,不能直接去查询result-count,否则会有警告,可能需要做下处理。另外,当百科查不到结果时,会有一个推荐的结果,是否可以返回?

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG]Result of search_baike is not complete

描述该问题

返回的结果被省略号省略了。

复现该问题

from baiduspider import BaiduSpider
from pprint import pprint

# 实例化BaiduSpider
spider = BaiduSpider()

# 搜索网页
print(spider.search_baike(query='python').plain)

预期结果

返回完整结果

实际结果

返回部分结果和省略号

系统

  • 操作系统: windows
  • Python版本: 3.8

其他描述

一些关于问题的其他的描述。

[BUG]

描述该问题

一个对该问题的清晰的描述。

复现该问题

请提供能够复现该问题的代码或步骤。

预期结果

一个对你想要的结果的清晰的描述。

实际结果

你实际得到的结果。

系统

  • 操作系统: 例如:MacOS
  • Python版本: 例如:3.8

其他描述

一些关于问题的其他的描述。

[BUG] No module named 'baiduspider.parser'

When running he demo.py as it presented at readme.md

python3 x.py

also tried python x.py didn't work

outputs are like

Traceback (most recent call last):
File "/root/tmp.py", line 1, in
from baiduspider import BaiduSpider
File "/usr/local/lib/python3.9/site-packages/baiduspider/init.py", line 19, in
from baiduspider.parser.parser import Parser
ModuleNotFoundError: No module named 'baiduspider.parser'

Python3.9 in debian10 with zsh, package path added

结果导出

项目能实现爬虫结果导出么?或者您可以提供给我一些结果导出的建议么?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.