Python 学习如何使用网络垃圾

Python 学习如何使用网络垃圾,python,web-scraping,Python,Web Scraping,我试图从一个网站上获取鞋子的名称和价格,但我收到一个错误消息:TimeoutError:[WinError 10060]连接尝试失败,因为连接方在一段时间后没有正确响应,或者因为连接主机没有响应而建立的连接失败 from urllib.request import urlopen from bs4 import BeautifulSoup url='https://www.eastbay.com/category/sport/casual/mens/shoes.html' driver=ur

我试图从一个网站上获取鞋子的名称和价格,但我收到一个错误消息:TimeoutError:[WinError 10060]连接尝试失败,因为连接方在一段时间后没有正确响应,或者因为连接主机没有响应而建立的连接失败

from urllib.request import urlopen
from bs4 import BeautifulSoup

url='https://www.eastbay.com/category/sport/casual/mens/shoes.html'

driver=urlopen(url)
page=driver.read()
driver.close()

html=BeautifulSoup(page, 'html.parser')

shoes=html.find_all('div',class_='product-container col')

filename='shoes.csv'
f=open('shoes.csv','w')
for each in shoes:
   title=each.find('div',class_='ProductName-primary').text
   price=each.find('div',class_='ProductPrice-original').text
   f.write(title + ',' + price)

f.close()

该站点很可能执行某种机器人检测并超时您的请求,因为它看起来不像来自实际的web浏览器。尝试添加HTTP头,如
连接
接受编码
接受语言
用户代理
ẃ与web浏览器将发送的内容相对应的第i个值。