鱼C论坛

 找回密码
 立即注册
查看: 1027|回复: 4

[已解决]爬虫问题

[复制链接]
发表于 2020-6-18 14:34:12 | 显示全部楼层 |阅读模式

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

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

x
想要爬这个网站的二级页面,出不来东西

https://kcls.bibliocommons.com/e ... art=2020-06-17%20TO

  1. import requests
  2. from lxml import etree
  3. from fake_useragent import UserAgent

  4. url = "https://kcls.bibliocommons.com/events/event_series?client_scope=events&ids=5eab1dbe9f683f2f002ef1b8%2C5ec71a24d75f424500deeb8f%2C5ebb06c0318ab13a002084eb%2C5ebf2c39171b7a2400152407%2C5ebb07163a6fc12f007e1df8"
  5. headers = {"User-Agent": UserAgent().random}

  6. res = requests.get(url, headers=headers)
  7. html = res.content.decode("utf-8")
  8. parse_html = etree.HTML(html)
  9. parse_html
  10. events_list = parse_html.xpath('//div/h2/a/@href')
  11. for event in events_list:
  12.     print(event)
复制代码
最佳答案
2020-6-18 16:44:48
  1. import requests

  2. url='https://kcls.bibliocommons.com/events/events/search?'
  3. headers={
  4.    
  5.     'Accept':'application/json, text/javascript, */*; q=0.01'
  6. }
  7. data={
  8.     'client_scope': 'events',
  9.     'query': 'q=online&start=20',
  10.     'facet_fields': 'branch_location_id,types,program,audiences,languages,is_virtual',
  11.     'local_start': '2020-06-17 TO',
  12.     'include_near_location': 'false'
  13. }
  14. request=requests.get(url,headers=headers,params=data).text
  15. print(request)
复制代码


你试下这个代码 是不是你想要的的数据 因为我英语不太好 也不知道你具体需要哪个数据  
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-6-18 16:27:15 | 显示全部楼层
我点开你给的URL  数据是通过JSON传到前端的  直接抓包拿到JSON地址 就行了 根本不需要lxml
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-18 16:28:41 | 显示全部楼层
而且这个网站有请求头反爬 爬的时候记得加  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-6-18 16:29:24 | 显示全部楼层
admintest166 发表于 2020-6-18 16:27
我点开你给的URL  数据是通过JSON传到前端的  直接抓包拿到JSON地址 就行了 根本不需要lxml

不是很懂诶,能加个QQ指导一下吗,感谢。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-6-18 16:44:48 | 显示全部楼层    本楼为最佳答案   
  1. import requests

  2. url='https://kcls.bibliocommons.com/events/events/search?'
  3. headers={
  4.    
  5.     'Accept':'application/json, text/javascript, */*; q=0.01'
  6. }
  7. data={
  8.     'client_scope': 'events',
  9.     'query': 'q=online&start=20',
  10.     'facet_fields': 'branch_location_id,types,program,audiences,languages,is_virtual',
  11.     'local_start': '2020-06-17 TO',
  12.     'include_near_location': 'false'
  13. }
  14. request=requests.get(url,headers=headers,params=data).text
  15. print(request)
复制代码


你试下这个代码 是不是你想要的的数据 因为我英语不太好 也不知道你具体需要哪个数据  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-22 03:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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