forward backward
把这两个作为两个链接.我想首先加载此页面,其中包含此链接并单击任何这些链接.注意[我不知道随机更改后点击它后会加载的URL]
解决方法 这是一个老帖子,但对于任何寻找答案的人来说,我遇到了类似的问题,并且能够解决它.我在cUrl中使用了PHP.通过cUrl链接的代码非常简单.
// Create a user agent so websites don't block you$userAgent = 'Googlebot/2.1 (http://www.Google.bot.com/bot.HTML)';// Create the initial link you want.$target_url = "http://www.example.com/somepage";// Initialize curl and following options$ch = curl_init();curl_setopt($ch,CURLOPT_USERAGENT,$userAgent);curl_setopt($ch,CURLOPT_URL,$target_url);curl_setopt($ch,CURLOPT_FAILONERROR,true);curl_setopt($ch,CURLOPT_FolLOWLOCATION,CURLOPT_autoREFERER,CURLOPT_RETURNTRANSFER,CURLOPT_TIMEOUT,10);// Grab the HTML from the page$HTML = curl_exec($ch);// Error handlingif(!$HTML){ handle error if page was not reachable,etc exit();}// Create a new DOM document to handle scraPing$dom = new DOMdocument();@$dom->loadHTML($HTML);// get your element,you can do this numerous ways like getting by tag,ID or using a DOMXPath object// This example gets elements with ID forward-link which might be a div or ul or li,etc// It then gets all the a Tags (links) within all those divs,uls,etc// Then it takes the first link in the array of links and then grabs the href from the link$search = $dom->getElementByID('forward-link');$forwardlink = $search->getElementsByTagname('a');$forwardlink = $forwardlink->item(0);$forwardlink = $getnamedItem('href');$href = $forwardlink->textContent;// Now that you have the link you want to follow/click to// Set the target_url for the cUrl to the new urlcurl_setopt($ch,$target_url);$HTML = curl_exec($ch);// do what you want with your new link!
这是一个很好的教程:php curl tutorial
总结以上是内存溢出为你收集整理的如何使用cURL单击链接.?全部内容,希望文章能够帮你解决如何使用cURL单击链接.?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)