Home  >  Article  >  Backend Development  >  编程 - curl、file_get_contents等PHP获取网页内容函数的问题

编程 - curl、file_get_contents等PHP获取网页内容函数的问题

WBOY
WBOYOriginal
2016-06-06 20:50:231062browse

该URL如果直接在浏览器输入访问能正确显示内容,但是用CURL或filegetcontents等函数或组件获取内容时会返回空字符串。 以前用PHP抓取百度词典的内容时会出现这种情况,前几天抓12306的数据时也发生了这种情况,请问他们是怎么识别的,有什么解决的办法吗?谢谢!

回复内容:

该URL如果直接在浏览器输入访问能正确显示内容,但是用CURL或filegetcontents等函数或组件获取内容时会返回空字符串。 以前用PHP抓取百度词典的内容时会出现这种情况,前几天抓12306的数据时也发生了这种情况,请问他们是怎么识别的,有什么解决的办法吗?谢谢!

1.user_agent 要设置成浏览器的 2.referrer 要设置正确 3.带上应该带上的cookie 4.其它附加东西

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn