gpt4 book ai didi

python - Web Scraping - 我需要登录 LinkedIn 才能进行 webscrape (scrapy)

转载 作者:太空宇宙 更新时间:2023-11-04 09:29:13 26 4
gpt4 key购买 nike

我目前正在为 Linkedin 创建网络抓取工具,但 LinkedIn 阻止我的机器人抓取数据,因为我没有登录任何帐户。我的目标基本上是抓取公司提供的任何工作机会,但我的问题主要是关于代码的登录方面。

我在 Python 3.X 上使用 scrapy 和 formrequest。

因此,我在网上寻找解决方案,formrequest 包似乎是我需要的答案。然而,经过多次尝试,它仍然无法正常工作。

import scrapy
from scrapy.http import FormRequest
from scrapy.utils.response import open_in_browser
from ..items import LinkedinItem


class LinkedinSpiderSpider(scrapy.Spider):
name = 'linkedin_spider'
start_urls = ['https://www.linkedin.com/login']

def parse(self, response):
token = response.css('form input::attr(value)').extract_first()
print(token)
return FormRequest.from_response(response, formdata={
'csrf_token': token,
'username': 'XXX@gmail.com',
'password': 'XXX'
}, callback=self.start_scraping)

def start_scraping(self, response):
open_in_browser(response)
items = LinkedinItem()
all_div_quotes = response.css('div.quote')

for quotes in all_div_quotes:
Job_offers = response.css('.disabled').css('::text').extract()
company = response.css('.job-card-search__company-name-link').css('::text').extract()
information = response.css('.job-card-search__description-snippet').css('::text').extract()

items['Job_offers'] = Job_offers
items['company'] = company
items['information'] = information

yield items

我添加了 open_in_browser 包以验证我是否正确登录并且浏览器打开到登录屏幕并且写着:请输入电子邮件地址

我希望我的浏览器打开主页并登录我的帐户。

谢谢

最佳答案

虽然我无法回答您最初的问题,但我可以告诉您,您的行为违反了LinkedIn's software extensions policy。 .

In order to protect our members' data and our website, we don't permit the use of any third party software, including "crawlers", bots, browser plug-ins, or browser extensions (also called "add-ons"), that scrapes, modifies the appearance of, or automates activity on LinkedIn's website.

注意这里。不仅许多网站采用了防止数据抓取的方法,而且众所周知,有些网站(包括 LinkedIn)会将开发人员告上法庭。

要以安全、合法的方式做您想做的事,请查看 LinkedIn's API page .

关于python - Web Scraping - 我需要登录 LinkedIn 才能进行 webscrape (scrapy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56331631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com