从网上找到一个大众的常用的天气接口:
上海:“ http://www.weather.com.cn/adat/cityinfo/101020100.html”
返回json子串:
{"weatherinfo":{"city":"上海","city_en":"shanghai","date_y":"2014年3月4日","date":"","week":"星期二","fchh":"11","cityid":"101020100","temp1":"11C~6C","temp2":"10C~5C","temp3":"8C~4C","temp4":"8C~6C","temp5":"8C~6C","temp6":"10C~5C","tempF1":"51.8F~42.8F","tempF2":"50F~41F","tempF3":"46.4F~39.2F","tempF4":"46.4F~42.8F","tempF5":"46.4F~42.8F","tempF6":"50F~41F","weather1":"小雨转多云","weather2":"多云转阴","weather3":"小雨","weather4":"小雨","weather5":"小雨转阴","weather6":"多云","img1":"7","img2":"1","img3":"1","img4":"2","img5":"7","img6":"99","img7":"7","img8":"99","img9":"7","img10":"2","img11":"1","img12":"99","img_single":"7","img_title1":"小雨","img_title2":"多云","img_title3":"多云","img_title4":"阴","img_title5":"小雨","img_title6":"小雨","img_title7":"小雨","img_title8":"小雨","img_title9":"小雨","img_title10":"阴","img_title11":"多云","img_title12":"多云","img_title_single":"小雨","wind1":"东北风3-4级转北风4-5级","wind2":"北风4-5级转东北风3-4级","wind3":"东风4-5级","wind4":"东风转东北风4-5级","wind5":"东北风3-4级","wind6":"东北风转东风3-4级","fx1":"东北风","fx2":"北风","fl1":"3-4级转4-5级","fl2":"4-5级转3-4级","fl3":"4-5级","fl4":"4-5级","fl5":"3-4级","fl6":"3-4级","index":"较冷","index_d":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index48":"较冷","index48_d":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index_uv":"最弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"适宜","index_co":"较舒适","st1":"10","st2":"3","st3":"9","st4":"2","st5":"7","st6":"2","index_cl":"不宜","index_ls":"不宜","index_ag":"易发"}}
内容格式倒是正确,信息也比较全, 可是没有指定日期的方式获取。
问题:
① 如何获取上海 当天和7天内的天气信息?
或者
② 能用正则将中国天气网的信息匹配出来?
url: http://www.weather.com.cn/weather/101020100.shtml
<div class="m m3" id="7d"><ul class="t clearfix"><li class='dn on' data-dn='7d1'><h1 id="今天">今天</h1><h2 id="日">3日</h2> <!-- 正则获取标签内容 --><big class="jpg50 d07"></big> <!-- 正则获取class内容 --><big class="jpg50 n07"></big> <!-- 正则获取class内容 --><p class="wea">小雨</p><!-- 正则获取标签内容 --><p class="tem tem1"><span>16</span><i>C</i><!-- 正则获取标签内容 --></p><p class="tem tem2"><span>13</span><i>C</i><!-- 正则获取标签内容 --></p><p class="win"><em><span title="东北风" class="NE"></span><span title="东风" class="E"></span></em><i>微风</i><!-- 正则获取标签内容 --></p><div class="slid"></div></li><!-- 以下正则匹配规则同上 --><li class='dn' data-dn='7d2'><h1 id="明天">明天</h1><h2 id="日">4日</h2><big class="jpg50 d07"></big><big class="jpg50 n07"></big><p class="wea">小雨</p><p class="tem tem1"><span>23</span><i>C</i></p><p class="tem tem2"><span>15</span><i>C</i></p><p class="win"><em><span title="东南风" class="SE"></span><span title="北风" class="N"></span></em><i>微风</i></p><div class="slid"></div></li><li class='dn' data-dn='7d3'><h1 id="后天">后天</h1><h2 id="日">5日</h2><big class="jpg50 d04"></big><big class="jpg50 n04"></big><p class="wea">雷阵雨</p><p class="tem tem1"><span>21</span><i>C</i></p><p class="tem tem2"><span>13</span><i>C</i></p><p class="win"><em><span title="东北风" class="NE"></span><span title="东北风" class="NE"></span></em><i>微风</i></p><div class="slid"></div></li><li class='dn' data-dn='7d4'><h1 id="周一">周一</h1><h2 id="日">6日</h2><big class="jpg50 d08"></big><big class="jpg50 n07"></big><p class="wea">中雨转小雨</p><p class="tem tem1"><span>15</span><i>C</i></p><p class="tem tem2"><span>10</span><i>C</i></p><p class="win"><em><span title="北风" class="N"></span><span title="北风" class="N"></span></em><i>3-4级</i></p><div class="slid"></div></li><li class='dn' data-dn='7d5'><h1 id="周二">周二</h1><h2 id="日">7日</h2><big class="jpg50 d08"></big><big class="jpg50 n08"></big><p class="wea">中雨</p><p class="tem tem1"><span>13</span><i>C</i></p><p class="tem tem2"><span>8</span><i>C</i></p><p class="win"><em><span title="北风" class="N"></span><span title="北风" class="N"></span></em><i>3-4级</i></p><div class="slid"></div></li><li class='dn' data-dn='7d6'><h1 id="周三">周三</h1><h2 id="日">8日</h2><big class="jpg50 d08"></big><big class="jpg50 n07"></big><p class="wea">中雨转小雨</p><p class="tem tem1"><span>13</span><i>C</i></p><p class="tem tem2"><span>9</span><i>C</i></p><p class="win"><em><span title="东北风" class="NE"></span><span title="东北风" class="NE"></span></em><i>微风</i></p><div class="slid"></div></li><li class='dn' data-dn='7d7'><h1 id="周四">周四</h1><h2 id="日">9日</h2><big class="jpg50 d02"></big><big class="jpg50 n02"></big><p class="wea">阴</p><p class="tem tem1"><span>14</span><i>C</i></p><p class="tem tem2"><span>9</span><i>C</i></p><p class="win"><em><span title="东北风" class="NE"></span><span title="东北风" class="NE"></span></em><i>微风</i></p><div class="slid"></div></li></ul><i class="line1"></i></div> <!-- 嵌套7天逐12小时精细化预报模块 开始--> </div>
将我注释的的内容匹配出来就行,不过这个方法麻烦了点,效率也不高。
求助。。。
回复讨论(解决方案)
找到了一个实时的接口:
http://weatherapi.market.xiaomi.com/wtr-v2/weather?cityId=101020100

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
