鱼C论坛

 找回密码
 立即注册
查看: 3340|回复: 17

[已解决]爬取

[复制链接]
发表于 2023-3-4 13:26:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
大佬们,这种情况是不是就不能爬取了
最佳答案
2023-3-4 17:42:40
对的,没有权限的资源自然也就不能爬取
屏幕截图(34).png
屏幕截图(33).png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-3-4 17:42:40 | 显示全部楼层    本楼为最佳答案   
对的,没有权限的资源自然也就不能爬取
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 17:47:43 | 显示全部楼层
isdkz 发表于 2023-3-4 17:42
对的,没有权限的资源自然也就不能爬取

好的,感谢感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 18:03:03 | 显示全部楼层
isdkz 发表于 2023-3-4 17:42
对的,没有权限的资源自然也就不能爬取

可以帮我看一下这个代码是哪里出问题了吗,怎么只能爬取十个,后面怎么爬取不到了呢,感谢感谢
  1. import requests
  2. import re
  3. from time import sleep
  4. from lxml import html
  5. etree = html.etree


  6. header = {
  7.    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
  8. }

  9. #解析标题和详情页的url
  10. url_01 = 'https://www.ting456.com/book/d45049.html'
  11. response = requests.get(url=url_01,headers=header).text
  12. tree = etree.HTML(response)
  13. li_list = tree.xpath('//*[@id="xima"]/div/li')
  14. for li in li_list:
  15.    
  16.     title = li.xpath('./a/text()')[0]
  17.     href = 'https://www.ting456.com' + li.xpath('./a/@href')[0]
  18.     print(title,href)
  19.     #print(href)
  20.     #解析动态参数
  21.     hre = li.xpath('./a/@href')[0]
  22.     pattern = re.compile('(/play/\d+?-\d-)(\d)(\.html)')
  23.     for i in pattern.findall(hre):
  24.         don_02 = f"{i[0]}{int(i[1]) + 1}{i[2]}"

  25.     # print(title,href)
  26.     #解析动态参数
  27.         url_02 = href
  28.         response = requests.get(url=url_02, headers=header).text
  29.         tree = etree.HTML(response)
  30.         page = tree.xpath('//*[@id="player"]/script[1]/text()')[0]
  31.         ex = 'now="(.+?)"'
  32.         don_01 = re.findall(ex, page, re.S)[0]

  33.         #解析音乐的url
  34.         url_03 = 'https://www.ting456.com/js/player/play.php'

  35.         parms = {
  36.             "url": don_01,
  37.             "from": "xima",
  38.             "s": "undefined",
  39.             "x": don_02
  40.         }
  41.         # s = "/ play / 45049 - 0 - {}.html".format(i)
  42.         # print(s)
  43.         #sleep(1)
  44.         result = requests.get(url=url_03, headers=header, params=parms).text
  45.         ex = 'mp3:"(.*?)"'
  46.         url_04 = re.findall(ex, result, re.S)[0]
  47.         #print(url_04)
  48.     #
  49.     # #请求音乐数据并保存
  50.         con = requests.get(url=url_04, headers=header).content
  51.         pattern = re.compile(r'[\\/:*?"<>|]')
  52.         title = pattern.sub("", title)
  53.         name = title + '.mp3'
  54.         f = open(name, 'wb')
  55.         f.write(con)
  56.         print(title,"保存完毕")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-4 20:33:46 | 显示全部楼层
哈岁NB 发表于 2023-3-4 18:03
可以帮我看一下这个代码是哪里出问题了吗,怎么只能爬取十个,后面怎么爬取不到了呢,感谢感谢

有没有报错?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 20:45:12 | 显示全部楼层

没有报错,直接就程序结束了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 20:52:53 | 显示全部楼层

就是这样,最后面的没有权限不爬取,但是十一十二这些还能爬,我这个程序不知道怎么就爬到十就结束了,就是因为url_04只输出10个,不知道为什么
屏幕截图(35).png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 20:57:52 | 显示全部楼层

找到原因了,是31行写进那个for循环了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-4 20:59:47 | 显示全部楼层
哈岁NB 发表于 2023-3-4 20:57
找到原因了,是31行写进那个for循环了

ok,我这里没跑出结果,也不知道网速太慢还是怎样
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 21:04:41 | 显示全部楼层
isdkz 发表于 2023-3-4 20:59
ok,我这里没跑出结果,也不知道网速太慢还是怎样

好的,请问这个报错是什么原因呀,我查的是访问太频繁码
  1. Traceback (most recent call last):
  2.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
  3.     httplib_response = self._make_request(
  4.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
  5.     six.raise_from(e, None)
  6.   File "<string>", line 3, in raise_from
  7.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
  8.     httplib_response = conn.getresponse()
  9.   File "D:\Program Files\python\lib\http\client.py", line 1322, in getresponse
  10.     response.begin()
  11.   File "D:\Program Files\python\lib\http\client.py", line 303, in begin
  12.     version, status, reason = self._read_status()
  13.   File "D:\Program Files\python\lib\http\client.py", line 272, in _read_status
  14.     raise RemoteDisconnected("Remote end closed connection without"
  15. http.client.RemoteDisconnected: Remote end closed connection without response

  16. During handling of the above exception, another exception occurred:

  17. Traceback (most recent call last):
  18.   File "D:\技能\python\venv\lib\site-packages\requests\adapters.py", line 489, in send
  19.     resp = conn.urlopen(
  20.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
  21.     retries = retries.increment(
  22.   File "D:\技能\python\venv\lib\site-packages\urllib3\util\retry.py", line 550, in increment
  23.     raise six.reraise(type(error), error, _stacktrace)
  24.   File "D:\技能\python\venv\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
  25.     raise value.with_traceback(tb)
  26.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
  27.     httplib_response = self._make_request(
  28.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
  29.     six.raise_from(e, None)
  30.   File "<string>", line 3, in raise_from
  31.   File "D:\技能\python\venv\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
  32.     httplib_response = conn.getresponse()
  33.   File "D:\Program Files\python\lib\http\client.py", line 1322, in getresponse
  34.     response.begin()
  35.   File "D:\Program Files\python\lib\http\client.py", line 303, in begin
  36.     version, status, reason = self._read_status()
  37.   File "D:\Program Files\python\lib\http\client.py", line 272, in _read_status
  38.     raise RemoteDisconnected("Remote end closed connection without"
  39. urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

  40. During handling of the above exception, another exception occurred:

  41. Traceback (most recent call last):
  42.   File "D:\技能\python\shengy\tunshi.py", line 34, in <module>
  43.     response = requests.get(url=url_02, headers=header).text
  44.   File "D:\技能\python\venv\lib\site-packages\requests\api.py", line 73, in get
  45.     return request("get", url, params=params, **kwargs)
  46.   File "D:\技能\python\venv\lib\site-packages\requests\api.py", line 59, in request
  47.     return session.request(method=method, url=url, **kwargs)
  48.   File "D:\技能\python\venv\lib\site-packages\requests\sessions.py", line 587, in request
  49.     resp = self.send(prep, **send_kwargs)
  50.   File "D:\技能\python\venv\lib\site-packages\requests\sessions.py", line 701, in send
  51.     r = adapter.send(request, **kwargs)
  52.   File "D:\技能\python\venv\lib\site-packages\requests\adapters.py", line 547, in send
  53.     raise ConnectionError(err, request=request)
  54. requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-4 21:09:17 | 显示全部楼层
哈岁NB 发表于 2023-3-4 21:04
好的,请问这个报错是什么原因呀,我查的是访问太频繁码

确实是,应该等一会儿就好
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-4 21:09:46 | 显示全部楼层
isdkz 发表于 2023-3-4 21:09
确实是,应该等一会儿就好

好的,感谢感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-5 09:11:55 | 显示全部楼层
isdkz 发表于 2023-3-4 21:09
确实是,应该等一会儿就好

请问一下大佬,我现在基础爬虫学完了,下一步该学什么呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-5 09:45:35 | 显示全部楼层
哈岁NB 发表于 2023-3-5 09:11
请问一下大佬,我现在基础爬虫学完了,下一步该学什么呢

进阶的话可以深入学一下http协议的知识,还有 js 也可以学一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-5 09:48:24 | 显示全部楼层
isdkz 发表于 2023-3-5 09:45
进阶的话可以深入学一下http协议的知识,还有 js 也可以学一下

好的,感谢感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-5 09:50:41 | 显示全部楼层
isdkz 发表于 2023-3-5 09:45
进阶的话可以深入学一下http协议的知识,还有 js 也可以学一下

想问一下,如果自己想找项目练手,该去哪里找呢,GitHub吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-5 09:57:04 | 显示全部楼层
哈岁NB 发表于 2023-3-5 09:50
想问一下,如果自己想找项目练手,该去哪里找呢,GitHub吗

对的,基本是去 github 上找,

这里有一些不错的爬虫项目:
https://www.zhihu.com/question/58151047

https://zhuanlan.zhihu.com/p/425241599
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-5 09:57:39 | 显示全部楼层
isdkz 发表于 2023-3-5 09:57
对的,基本是去 github 上找,

这里有一些不错的爬虫项目:

好的,感谢感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-24 19:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表