Python gets a week of weather content

Source: Internet
Author: User

In learning Python, see a Python script for getting the weather,, this is too much trouble, Wrote a simple script with BeautifulSoup,

#-*-coding:cp936-*-import sysimport httplibimport reimport requestsimport jsonimport urllibfrom BS4 Import BeautifulSo Updef Wea ():    r = requests.get (' ')    print r.status_code    f = open (' 1.html ', ' w+ ')    f.write (r.content)    f.close ()    soup = beautifulsoup (open (' 1.html '), "lxml")    #print Soup.title.encode (' GB18030 ')    data = {}    for link in soup.find_all (' P ', Attrs ={"class": "Wt_fc_c0_i_day"}):        temp = link.find_next_sibling (' P ', Attrs ={"class": "Wt_fc_c0_i_temp"})        WEA  = Link.find_next ("img")        Data[link.text] = temp.text + wea[' title '] for            text in data:        print text,data[text]if __name__ = = ' __main_ _ ':    Wea ()

Python gets a week of weather content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.