Reputation: 35
I am trying to scrape information from this webpage.
Here is a screenshot should the webpage not work.
I am trying to print the text in the first <span>
element.
I copied the XPath as provided by the Inspect Element view in Google Chrome (see screenshot above), and
//*[@id="main"]/div[1]/div/div/div[2]/p[1]/span[1]/text()
was copied to my clipboard.
from lxml import html
import requests
# get alert info
page = requests.get( 'https://www.msn.com/en-us/weather/weatheralerts/Beverly%20Hills,California,Unite%20d%20States/we-city?weadegreetype=F&day=1&ocid=ansmsnweather')
tree = html.fromstring(page.content)
alertInfo = tree.xpath( '//*[@id="main"]/div[1]/div/div/div[2]/p[1]/span[1]/text()')
print alertInfo
[]
. I am sure that the URL string is correct. Why did this occur?
I also tried alertInfo = tree.xpath( '//span/text()')
to see if I could just pick out the element in the list, but even that returned an empty list.
Thanks.
Upvotes: 0
Views: 520
Reputation: 2737
Upvotes: 1