scrape_twitter



In [1]:
import requests, lxml.html

In [2]:
response = requests.get("https://twitter.com/Metrorailinfo")
doc = lxml.html.fromstring(response.content)

In [13]:
for el in doc.cssselect("div.js-tweet-text-container"):
    print(el.text_content().strip())


Yellow/Green Line: Normal service has resumed at Archives.
Yellow/Green Line: Expect residual delays to Mount Vernon Square & Greenbelt due to earlier police activity at Archives.
Orange Line: Normal service has resumed at Dunn Loring.
Orange Line: Expect residual delays to New Carrollton due to an earlier train malfunction at Dunn Loring.
Orange Line: Expect delays to New Carrollton due to a disabled train at Dunn Loring.
Green Line: Normal service has resumed between Fort Totten & Prince George's Plaza.
Org/Blu/Sil Line: Normal service has resumed at Farragut West.
Org/Blu/Sil Line: Expect residual delays to Largo Town Center & New Carrollton due to an earlier track problem outside Farragut West.
Blue/Silver/Orange Line: Normal service has resumed outside Stadium-Armory.
Green Line: Delays possible in both directions due to scheduled track work btwn Ft. Totten & Prince George's Plaza.
Blue/Silver/Orange Line: Expect residual delays in both directions due to an earlier switch problem outside Stadium-Armory.
Blue/Silver/Orange: Due to a switch problem outside Stadium-Armory, trains are experiencing delays in both directions. 10:14a #wmata
Blue/Silver/Orange Line: Expect delays in both directions due to a switch problem outside Stadium-Armory.
Blu/Sil/Org Line: Expect delays to Vienna, Franconia, & Wiehle-Reston East due to a switch problem outside Stadium-Armory.
Yellow Line: All trains are operating btwn Huntington & Mt Vernon Sq only due to scheduled track work near Fort Totten.
Red Line: Normal service has resumed outside Friendship Heights.
Red Line: No longer single tracking. Residual delays continue in both directions due to an earlier track problem outside Friendship Hghts.
Red Line-good track inspection, 2-track service resuming Friendship Heights to Medical Center. 8:47a #wmata
Red Line: Outbound trains are bypassing Bethesda to reduce single tracking delays. Use inbound trains for this station.
Red Line: Single tracking btwn Friendship Hghts & Medical Ctr due to a track problem outside Friendship Hghts. Delays in both directions.

In [18]:
for i, el in enumerate(doc.cssselect("div.js-tweet-text-container")):
    print(i, el.text_content().strip())
    print("-------------------------------------")


0 Yellow/Green Line: Normal service has resumed at Archives.
-------------------------------------
1 Yellow/Green Line: Expect residual delays to Mount Vernon Square & Greenbelt due to earlier police activity at Archives.
-------------------------------------
2 Orange Line: Normal service has resumed at Dunn Loring.
-------------------------------------
3 Orange Line: Expect residual delays to New Carrollton due to an earlier train malfunction at Dunn Loring.
-------------------------------------
4 Orange Line: Expect delays to New Carrollton due to a disabled train at Dunn Loring.
-------------------------------------
5 Green Line: Normal service has resumed between Fort Totten & Prince George's Plaza.
-------------------------------------
6 Org/Blu/Sil Line: Normal service has resumed at Farragut West.
-------------------------------------
7 Org/Blu/Sil Line: Expect residual delays to Largo Town Center & New Carrollton due to an earlier track problem outside Farragut West.
-------------------------------------
8 Blue/Silver/Orange Line: Normal service has resumed outside Stadium-Armory.
-------------------------------------
9 Green Line: Delays possible in both directions due to scheduled track work btwn Ft. Totten & Prince George's Plaza.
-------------------------------------
10 Blue/Silver/Orange Line: Expect residual delays in both directions due to an earlier switch problem outside Stadium-Armory.
-------------------------------------
11 Blue/Silver/Orange: Due to a switch problem outside Stadium-Armory, trains are experiencing delays in both directions. 10:14a #wmata
-------------------------------------
12 Blue/Silver/Orange Line: Expect delays in both directions due to a switch problem outside Stadium-Armory.
-------------------------------------
13 Blu/Sil/Org Line: Expect delays to Vienna, Franconia, & Wiehle-Reston East due to a switch problem outside Stadium-Armory.
-------------------------------------
14 Yellow Line: All trains are operating btwn Huntington & Mt Vernon Sq only due to scheduled track work near Fort Totten.
-------------------------------------
15 Red Line: Normal service has resumed outside Friendship Heights.
-------------------------------------
16 Red Line: No longer single tracking. Residual delays continue in both directions due to an earlier track problem outside Friendship Hghts.
-------------------------------------
17 Red Line-good track inspection, 2-track service resuming Friendship Heights to Medical Center. 8:47a #wmata
-------------------------------------
18 Red Line: Outbound trains are bypassing Bethesda to reduce single tracking delays. Use inbound trains for this station.
-------------------------------------
19 Red Line: Single tracking btwn Friendship Hghts & Medical Ctr due to a track problem outside Friendship Hghts. Delays in both directions.
-------------------------------------