我需要将外部网页(非本地)加载到我的网站(某些链接)中,但只是其中的一部分。 这样做有什么选择?加载HTML页面并修改部分
1
A
回答
1
这取决于外部页面是本地还是不同的域。如果它是本地的,你可以在jQuery库中使用$ .load()。这有一个可选的参数来指定哪些元素在远程DOM加载它:
$("#links").load("/Main_Page #jq-p-Getting-Started li");
如果页面上的其他领域,你需要一个代理脚本。你可以用PHP和phpQuery(php的jQuery端口)库来做到这一点。您只需使用file_get_contents()来获取实际的remote-dom,然后根据类似jQuery的选择器提取所需的元素。
0
$f = fopen('http://www.quran.az/2/255', 'r');
等等...
0
要加载.NET中的网页,使用HttpWebRequest类。
示例从MSDN,here采取:
private string StringGetWebPage(String uri)
{
const int bufSizeMax = 65536; // max read buffer size conserves memory
const int bufSizeMin = 8192; // min size prevents numerous small reads
StringBuilder sb;
// A WebException is thrown if HTTP request fails
try
{
// Create an HttpWebRequest using WebRequest.Create (see .NET docs)!
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
// Execute the request and obtain the response stream
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
// Content-Length header is not trustable, but makes a good hint.
// Responses longer than int size will throw an exception here!
int length = (int)response.ContentLength;
// Use Content-Length if between bufSizeMax and bufSizeMin
int bufSize = bufSizeMin;
if (length > bufSize)
bufSize = length > bufSizeMax ? bufSizeMax : length;
// Allocate buffer and StringBuilder for reading response
byte[] buf = new byte[bufSize];
sb = new StringBuilder(bufSize);
// Read response stream until end
while ((length = responseStream.Read(buf, 0, buf.Length)) != 0)
sb.Append(Encoding.UTF8.GetString(buf, 0, length));
}
catch (Exception ex)
{
sb = new StringBuilder(ex.Message);
}
return sb.ToString();
}
注意这将返回整个页面而不是它只是一个部分。然后,您需要筛选页面以查找您要查找的信息。
0
相关问题
- 1. 部分加载asp.net页面
- 2. AJAX部分页面加载?
- 3. 如何在每次页面加载时更改html页面部分
- 4. 加载.HTML,修改它并插入iframe?
- 5. 在页面加载之前修改html页面中所有脚本的src
- 6. 如何修改perl变量并重新加载页面?
- 7. JQTouch加载外部html页面
- 8. Html页面加载在底部
- 9. 加载外部页面并插入Javascript?
- 10. 更改html表单值,加载页面并点击按钮
- 11. ajax从另一页面部分加载
- 12. Facebook粉丝页面只部分加载
- 13. PHP if语句停止加载HTML页面的其余部分
- 14. 如何重新加载HTML页面部分
- 15. 避免使用requirejs呈现部分加载的HTML页面
- 16. 如何加载当前显示的HTML页面的一部分?
- 17. 在WebDriver中加载页面之前删除部分HTML - Selenium&Python
- 18. 在div中加载外部页面并将其更改为
- 19. Jsoup没有加载完整的HTML页面,它只加载部分
- 20. 重新加载页面的一部分并更改URL示例说明
- 21. 当页面加载时更改html页面位置
- 22. jsp页面未从html页面加载
- 23. html页面加载消息
- 24. 修改表html用PHP页面显示
- 25. HTML文件加载部分
- 26. 用javascript加载部分html
- 27. 修复 - 分页休息页面加载了ajax请求
- 28. 仅在第一次加载时加载页面的一部分
- 29. 使用PHP来读取静态HTML页面,添加元标记,然后加载修改页面
- 30. 仅加载页面更改
页面不是本地的,asp.net中是否有任何图书馆? – Wineshtain 2009-08-31 20:32:43