我也查过其他帖子,但解决办法似乎没有奏效。我一直得到AttributeError:“module”对象没有属性“urlopen”错误。如果你有什么想法,我会非常感激的。在
from lxml import html
import requests
import urllib3
page = requests.get('http://www.sfbos.org/index.aspx?page=18701')
tree = html.fromstring(page.content)
#This will create a list of buyers:
proposal_doc_date = tree.xpath('//ul[@title="Date List"]/li/a/text()')
pdf_url = tree.xpath('//ul[@title="Date List"]/li/a/@href')
print 'Proposal Date ', proposal_doc_date
print 'Proposal PDF ', pdf_url
def download_pdf(url_list):
for i in url_list:
response = urllib3.urlopen(i)
file = open(proposal_doc_date[i], 'wb')
file.write(response.read())
file.close()
print("Completed")
download_pdf(pdf_url)
您同时导入了requests和{a2},它们的目的相同(请求构建在urllib3之上)。以下是如何使用请求执行此操作:
和urllib3中的类似场景:
^{2}$对于流式请求和在文件流式传输时将响应写入文件,还有其他各种各样的事情可以做。查看相应项目的文档了解更多。在
urlopen似乎是urllib3的方法。connectionpool.HTTPConnectionPool班级
https://urllib3.readthedocs.io/en/latest/pools.html#urllib3.connectionpool.HTTPConnectionPool.urlopen
相关问题 更多 >
编程相关推荐