发布请求无效

时间:2016-01-23 11:12:00

标签: python web-scraping

我正在尝试创建一个可以通过帖子请求成功告诉你天气的程序。

我正在尝试搜索网站上的天气并将信息提取到一个程序上,然后在网站上搜索一个位置(由用户编写)以查找天气,但它似乎无法正常工作。我不确定代码有什么问题。评论和任何建议将不胜感激。

import urllib.request
import urllib.parse
import re
from bs4 import BeautifulSoup

location = input('Your location you would like  to know for the weather ' )
print(location)

#http://www.wunderground.com/cgi-bin/findweather/getForecast?   query=bolton&MR=1
url=(r'http://www.wunderground.com' )
values = {
   'query':'location', 
     }

print (values) 
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')
req = urllib.request.Request(url,data)
resp = urllib.request.urlopen(req)
respData = resp.read()

print(respData)

paragraphs = re.findall(r'<p>(.*?)</p>',str(respData))

for eachP in paragraphs:
  print(eachP)

0 个答案:

没有答案
相关问题