Python戴尔驱动程序下载

时间:2018-01-13 05:45:16

标签: python beautifulsoup href urllib2

我一直在尽力使用Beautifulsoup4为驱动程序获取所有dl。但它会返回我不需要的链接。我认为它们在某种程度上是隐藏的,对于我的生活,我无法将它们弄出来。

here是我尝试废弃的页面:http://www.dell.com/support/home/us/en/19/product-support/servicetag/1h1c5p1/drivers

from bs4 import BeautifulSoup
import urllib2

resp = urllib2.urlopen("http://www.gpsbasecamp.com/national-parks")
soup = BeautifulSoup(resp, from_encoding=resp.info().getparam('charset'))

for link in soup.find_all('a', href=True):
print link['href']

1 个答案:

答案 0 :(得分:2)

驱动程序链接由js加载,因此通常您必须使用selenium或类似的客户端。但是在这种情况下,所有的驱动程序信息都以json格式提供,在&text; / preloaded'脚本标记。

from bs4 import BeautifulSoup
import urllib2
import json

resp = urllib2.urlopen("http://www.dell.com/support/home/us/en/19/product-support/servicetag/1h1c5p1/drivers")
soup = BeautifulSoup(resp, 'html.parser', from_encoding=resp.info().getparam('charset'))
data = json.loads(soup.find('script', type='text/preloaded').text)

for item in data:
    print 'Name', item['driverName']
    print 'Link', item['fileFrmtInfo']['httpFileLocation']