所以这里的代码是我用来首先提取左上角的时间。
import qgrid
import webbrowser
import requests
from bs4 import BeautifulSoup
page = requests.get('http://www.meteo.gr/cf.cfm?city_id=14') #sending the request to take the html file.
soup = BeautifulSoup(page.content, 'html.parser') #creating beautifulSoup object of the html code.
four_days = soup.find(id="prognoseis")#PINPOINTING to the section that i want to focus (the outer).
#Selecting specific elements , having as my base the seven_day.
periods = [p.get_text() for p in four_days.select(".perhour-rowmargin .innerTableCell-fulltime")]
#creating a Data Frame via pandas to print it TABLE-like.
import pandas as pd
weather = pd.DataFrame({"period ": periods})
print weather
我查了一个很好的教程,开始了解它。 在four_days对象中,我保留了包含在' prognoseis'中的html代码部分,这就是我想要的信息。 在句点对象之后,我选择包含我想要的信息的元素,并作为第二个参数指定我想要提取的文本。
代码运行并给我空。