找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 63|回复: 6

求php大神帮忙解决个curl问题,可付费

[复制链接]

21

主题

88

回帖

297

积分

中级会员

积分
297
发表于 2019-3-16 19:02:01 | 显示全部楼层 |阅读模式
本帖最后由 cnzmz 于 2019-3-16 20:11 编辑

补充一下:用python也能获取到源码,不出现验证码,python源码在最下面,就是php的curl死活不行

用php curl函数抓取谷歌学术搜索结果的时候,一直会出现google的人机验证,我原以为是谷歌限制了我的服务器ip,于是我用这个服务器搭建了一个http代理,自己的浏览器用这个代理访问google学术,无论怎么刷新怎么搜索,都不会出现验证码。那么问题应该不是出现在ip上面,然后我又在curl函数里加入了header信息,加入了UA,但还是出现验证码,不知道是不是我没加正确。

以下为我写的curl函数代码,我自己浏览器里面设置这个http代理访问没有任何问题,用下面的函数访问就给我蹦出了个人机验证

跪求php大神能帮忙解决,可付费

[ol]
  • ';
  • print_r($a);
  • echo '';[/ol]复制代码

    补充一下,用python也能获取到源码,不会出现机器人验证
    [ol]
  • def requests_html(url):
  •         headers = {        
  •         'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  •         'Accept-Encoding':'gzip, deflate, sdch',
  •         'Accept-Language':'zh-CN,zh;q=0.8',
  •         'Cache-Control':'no-cache',
  •         'Connection':'keep-alive',
  •         'DNT':'1',
  •         'Pragma':'no-cache',
  •         'Upgrade-Insecure-Requests':'1',
  •         'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
  •         }
  •         # proxies = {'http':'127.0.0.1:1080','https':'127.0.0.1:1080'}
  •         proxies = {"http": "http://user:pass@ip:port"}
  •         r = requests.get(url,headers=headers,timeout=5,proxies=proxies)
  •         status_code = r.status_code
  •         # print status_code
  •         if status_code != 200:
  •                 pass
  •         else:
  •                 coding = r.encoding.strip().lower()
  •                 # print coding
  •                 if coding == 'utf-8':        
  •                         html = r.content
  •                         # print html
  •                         return html                        
  •                 else:
  •                         html = r.text#.encode(coding).decode('utf8').encode('utf8')
  •                         # print html
  •                         return html
  • [/ol]复制代码
  • 回复

    使用道具 举报

    21

    主题

    88

    回帖

    297

    积分

    中级会员

    积分
    297
     楼主| 发表于 2019-3-16 19:29:20 | 显示全部楼层
    自己来终结0回复的尴尬
    回复

    使用道具 举报

    14

    主题

    36

    回帖

    142

    积分

    注册会员

    积分
    142
    发表于 2019-3-16 19:41:48 | 显示全部楼层
    来路加上试试,不过google就算了 代理也不行
    回复

    使用道具 举报

    21

    主题

    88

    回帖

    297

    积分

    中级会员

    积分
    297
     楼主| 发表于 2019-3-16 19:55:15 | 显示全部楼层

    rlonnet 发表于 2019-3-16 19:41

    来路加上试试,不过google就算了 代理也不行

    来路加上也不行,

    回复

    使用道具 举报

    21

    主题

    88

    回帖

    297

    积分

    中级会员

    积分
    297
     楼主| 发表于 2019-3-16 19:41:00 | 显示全部楼层
    补充一下,用python的request也能获取到源码,不出现验证码
    回复

    使用道具 举报

    48

    主题

    395

    回帖

    1002

    积分

    金牌会员

    积分
    1002
    发表于 2019-3-16 20:12:28 | 显示全部楼层

    lzhd24 发表于 2019-3-16 20:24

    感动的我都哭了,我去研究下,有结果了来反馈;请接下我的膝盖
    回复

    使用道具 举报

    21

    主题

    88

    回帖

    297

    积分

    中级会员

    积分
    297
     楼主| 发表于 2019-3-16 20:24:01 | 显示全部楼层

    lzhd24 发表于 2019-3-16 20:24

    用这个办法,还是会出现机器人验证,大佬可否加个QQ请教一下?
    回复

    使用道具 举报

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

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-4-20 04:59 , Processed in 0.019379 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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