任何人都可以帮我从blabla汽车的网址中提取骑手的详细信息或者请一些网页潦草的想法
从blabla汽车网站的网址中提取第一个5000次乘车详情
我是Web绘图和python的新手。所以任何人都提出了一些提示来完成任务
首先,你应该总是考虑你的抓点起点。在这种情况下,https://www.blablacar.in/search-car-sharing看起来相当不错,因为有最流行的路线链接。
以下是您可能要遵循的管道:
USER_AGENT
(在settings.py
中)设置为自定义内容以获得403响应。DOWNLOAD_DELAY
设置为像0.5
这样的东西不被禁止(可能需要使值更大)。start_urls = ['https://www.blablacar.in/search-car-sharing']
parse
方法,该方法将产生路由页面的请求。parse_route
方法,该方法将生成有关游乐设施的信息并遵循分页。这就是parse
方法的样子:
def parse(self, response):
for a_tag in response.css('.search-empty__meeting-points a'):
yield response.follow(a_tag, self.parse_route)
这里是parse_route
示例,解析骑行的名称和日期:
def parse_route(self, response):
for trip in response.css('.trip-search-results li'):
item = {}
item['name'] = trip.css('.ProfileCard-info--name::text').extract_first().strip()
item['date'] = trip.css('.description .time::attr(content)').extract_first()
yield item
for a_tag in response.css('.pagination .next:not(.disabled) a'):
yield response.follow(a_tag, self.parse_route)
希望这能让您直观了解如何解决任务。