从网上找到一个大众的常用的天气接口:
上海:“ 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

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.


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

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.