从 LS 获取城市列表时遇到问题
我正在努力获取一系列 LS 城市... file_get_contents() 在其路障上返回一个空的下拉列表,要求您选择城市。不幸的是它是空的...所以我认为它来自 ajax 请求。但查看页面时,我在页面上没有看到任何 ajax 请求。然后我尝试了 CURL,认为也许模拟浏览器会有所帮助......下面的代码没有任何影响。
$ch = curl_init("http://www.URL.com/");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
$result=curl_exec($ch);
var_dump($result);
有人对如何获得可用区域的可靠列表有任何想法吗?
I'm struggling getting an array of LS cities... file_get_contents() returns an empty dropdown on their roadblock requiring you to select cities. Unfortunately it's empty... so then I thought it was coming from an ajax request. But looking at the page I don't see any ajax requests on the page. Then I tried CURL, thinking that maybe simulating a browser would help... the below code had no affect.
$ch = curl_init("http://www.URL.com/");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
$result=curl_exec($ch);
var_dump($result);
Does anyone have any ideas on how I can get a solid list of available areas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经了解了他们如何填充城市列表,并在下面创建了一些您可以使用的示例代码。
城市列表作为 JSON 字符串存储在其中一个 javascript 文件中,并且该列表实际上是从另一个 javascript 文件填充的。文件的名称似乎有些随机,但根名称保持不变。
包含城市 JSON 的 JS 文件示例为 hXXp://a3.ak.lscdn.net/deals/system/javascripts/bingy-81bf24c3431bcffd317457ce1n434ca9.js 填充列表的脚本为hXXp://a2.ak.lscdn.net/deals/system/javascripts/confirm_city-81bf24c3431bcffd317457ce1n434ca9.js 但对我们来说这是无关紧要的。
我们需要使用新的curl会话加载他们的主页,查找唯一的javascript URL(即bingy脚本)并使用curl获取它。然后我们需要找到 JSON 并将其解码为 PHP,以便我们可以使用它。
这是我想出的对我有用的脚本:
一些重要的注意事项:
如果他们决定更改 javascript 文件名,这将无法工作。
如果他们重命名保存城市的变量名称,这将不起作用。
如果他们修改 json 以跨越多行,这将不起作用(这不太可能,因为它使用额外的带宽)
如果他们改变了 json 对象的结构,这将不起作用。
无论如何,根据他们的修改,重新开始工作可能很简单,但这是一个潜在的问题。他们也可能不太可能进行这些后勤更改,因为这需要修改许多文件,然后需要更多测试。
希望有帮助!
I have found out how they populate the list of cities and created some sample code below you can use.
The list of cities is stored as a JSON string in one of their javascript files, and the list is actually populated from a different javascript file. The names of the files appear to be somewhat random, but the root name remains the same.
An example of the JS file with the city JSON is hXXp://a3.ak.lscdn.net/deals/system/javascripts/bingy-81bf24c3431bcffd317457ce1n434ca9.js The script that populates the list is hXXp://a2.ak.lscdn.net/deals/system/javascripts/confirm_city-81bf24c3431bcffd317457ce1n434ca9.js but for us this is inconsequential.
We need to load their home page with a new curl session, look for the unique javascript URL that is the bingy script and fetch that with curl. Then we need to find the JSON and decode it to PHP so we can use it.
Here is the script I came up with that works for me:
Some important notes:
If they decide to change the javascript file names, this will fail to work.
If they rename the variable name that holds the cities, this will fail to work.
If they modify the json to span multiple lines, this will not work (this is unlikely because it uses extra bandwidth)
If they change the structure of the json object, this will not work.
In any case, depending on their modifications it may be trivial to get working again, but it is a potential issue. They may also be unlikely to make these logistical changes because it would require modifications to a number of files, and then require more testing.
Hope that helps!
也许有点晚了,但您不需要耦合到我们的 JavaScript 来获取城市列表。我们为此提供了一个 API:
https://sites.google。 com/a/hungrymachine.com/livingsocial-api/home/cities
Perhaps a bit late, but you don't need to couple to our JavaScript to obtain the cities list. We have an API for that:
https://sites.google.com/a/hungrymachine.com/livingsocial-api/home/cities