Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This page source works in your playground example but I can't get it to otherwise #57

Open
chimmel opened this issue May 23, 2020 · 5 comments

Comments

@chimmel
Copy link

chimmel commented May 23, 2020

$doc = hQuery::fromUrl('https://www.realtor.com/'); works, but any actual property URL throws
( ! ) Notice: Undefined offset: 2 in /home/vendor/duzun/hquery/src/hQuery.php on line 1152
but properties' urls work in your playground example runner? What am I missing?

@chimmel chimmel changed the title Trouble reacclimating; how do I get it to work? Trouble acclimating; how do I get it to work? May 23, 2020
@chimmel chimmel changed the title Trouble acclimating; how do I get it to work? This page source works in your playground example but I can't get it to otherwise May 24, 2020
@duzun
Copy link
Owner

duzun commented May 24, 2020

You have a Notice, not Error or even Warning - nothing serious.

Try adding error_reporting(E_ALL & ~E_NOTICE); at the begining of the file.

I'll look into the cause of this Notice, nonetheless.

@duzun
Copy link
Owner

duzun commented May 24, 2020

Looks like for some reason the response from the server starts with:
HTTP/2 200

while the library expects it to starts with something like:
HTTP/1.1 200 OK

The notice is about the missing status message "OK" - nothing wrong actually.

@chimmel
Copy link
Author

chimmel commented May 25, 2020

Thanks for the input. How do you get that though? HTTP/2 vs. HTTP/1.1? When I try in your playground it says STATUS: 200 OK

@chimmel
Copy link
Author

chimmel commented May 25, 2020

I added error_reporting(E_ALL & ~E_NOTICE); and var_dump($doc); returns
/home/classes/PropertyPage.php:39:boolean false

@duzun
Copy link
Owner

duzun commented May 25, 2020

hQuery::fromUrl uses my implementation of the HTTP through fsockopen().
I do not recommend it for advanced use cases. It is there originally for the ease of use and to avoid extra dependencies. But I recommend everybody to use some other method for fetching the HTML and feed it to hQuery::fromHTML($html, $url=null).
See #26 for some details and the README.

In any case, hQuery::fromUrl returns FALSE for any HTTP response but 200.
Try var_dump(hQuery::$last_http_result) to get some details on the HTTP response. Or even better, use a PSR-7 library to fetch the document.

@duzun duzun mentioned this issue Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants