Python 花旗自行车数据下载

Python 花旗自行车数据下载,python,web-scraping,Python,Web Scraping,大师 我试图在citibike数据页上提取URL并下载这些zip文件。但是,以下代码返回null。有人能给点提示吗?谢谢你的帮助 from bs4 import BeautifulSoup from urllib.request import Request, urlopen import re req = Request("https://s3.amazonaws.com/tripdata/index.html") html_page = urlopen(req) soup = Beaut

大师

我试图在citibike数据页上提取URL并下载这些zip文件。但是,以下代码返回null。有人能给点提示吗?谢谢你的帮助

from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import re

req = Request("https://s3.amazonaws.com/tripdata/index.html")
html_page = urlopen(req)

soup = BeautifulSoup(html_page, "lxml")

links = []
for link in soup.findAll('a'):
    links.append(link.get('href'))

print(links)

请求的页面实际上是“空的”(不包含链接)。所需链接来自另一个XML格式的URL

您可以在下面尝试获得所需的输出:

import requests
from lxml import etree

r = requests.get('https://s3.amazonaws.com/tripdata')
source = etree.fromstring(r.content)

for item in source.xpath('//*'):
    if item.text and item.text.endswith('zip'):
        print('https://s3.amazonaws.com/tripdata/' + item.text)

请求的页面实际上是“空的”(不包含链接)。所需链接来自另一个XML格式的URL

您可以在下面尝试获得所需的输出:

import requests
from lxml import etree

r = requests.get('https://s3.amazonaws.com/tripdata')
source = etree.fromstring(r.content)

for item in source.xpath('//*'):
    if item.text and item.text.endswith('zip'):
        print('https://s3.amazonaws.com/tripdata/' + item.text)

工作起来很有魅力!工作起来很有魅力!这里有一堆操作,但你没有描述它们中的哪一个没有按照预期的方式运行。这里有一堆操作,但你没有描述它们中的哪一个没有按照预期的方式运行以及如何运行。