Python 3.x I';I’我正试图从印度创业公司的网站上搜刮
我知道这不是一个错误,但我不知道如何抓取startup india网站,我正试图点击startup india提供的一些网站,但我不能点击它们,因为scrapy不能点击网站,我拥有的任何信息都只能通过点击链接抓取Python 3.x I';I’我正试图从印度创业公司的网站上搜刮,python-3.x,web-scraping,scrapy,Python 3.x,Web Scraping,Scrapy,我知道这不是一个错误,但我不知道如何抓取startup india网站,我正试图点击startup india提供的一些网站,但我不能点击它们,因为scrapy不能点击网站,我拥有的任何信息都只能通过点击链接抓取 import scrapy from selenium import webdriver import os class ProductSpider(scrapy.Spider): name = "product_spider" allowed_d
import scrapy
from selenium import webdriver
import os
class ProductSpider(scrapy.Spider):
name = "product_spider"
allowed_domains = ['https://www.startupindia.gov.in/']
start_urls = ['https://www.startupindia.gov.in/content/sih/en/search.html?industries=sih:industry/advertising&states=sih:location/india/andhra-pradesh&stages=Prototype&roles=Startup&page=0']
def __init__(self):
cwd = os.getcwd()
self.driver = webdriver.Chrome("C:/Users/RAJ/PycharmProjects/WebCrawler/WebCrawler/WebCrawler/spiders/chromedriver.exe")
self.profile = []
def parse(self, response):
self.driver.get(response.url)
while True:
next = self.driver.find_element_by_xpath('//*[@id="persona-results"]/div[1]/div/a/div[1]')
try:
next.click()
# get the data and write it to scrapy items
except:
break
self.driver.close()
顺便说一句,我的最终目标是获得所有的个人资料细节,但我不知道怎么做
(注:这是我第一次做网页抓取)这听起来像是关于抓取文档的教程,如下所示。通常,您可以尝试参考
#跟随作者页面的链接
,右键单击并查看“单击”位置,以在所需网页上获取css/xpath
或者,你可以随意分享你所拥有的。
希望这有帮助
import scrapy
class AuthorSpider(scrapy.Spider):
name = 'author'
start_urls = ['http://quotes.toscrape.com/']
def parse(self, response):
# follow links to author pages
for href in response.css('.author + a::attr(href)'):
yield response.follow(href, self.parse_author)
# follow pagination links
for href in response.css('li.next a::attr(href)'):
yield response.follow(href, self.parse)
def parse_author(self, response):
def extract_with_css(query):
return response.css(query).get(default='').strip()
yield {
'name': extract_with_css('h3.author-title::text'),
'birthdate': extract_with_css('.author-born-date::text'),
'bio': extract_with_css('.author-description::text'),
}
这听起来类似于下面关于Scrapy文档的教程。通常,您可以尝试参考
#跟随作者页面的链接
,右键单击并查看“单击”位置,以在所需网页上获取css/xpath
或者,你可以随意分享你所拥有的。
希望这有帮助
import scrapy
class AuthorSpider(scrapy.Spider):
name = 'author'
start_urls = ['http://quotes.toscrape.com/']
def parse(self, response):
# follow links to author pages
for href in response.css('.author + a::attr(href)'):
yield response.follow(href, self.parse_author)
# follow pagination links
for href in response.css('li.next a::attr(href)'):
yield response.follow(href, self.parse)
def parse_author(self, response):
def extract_with_css(query):
return response.css(query).get(default='').strip()
yield {
'name': extract_with_css('h3.author-title::text'),
'birthdate': extract_with_css('.author-born-date::text'),
'bio': extract_with_css('.author-description::text'),
}
如果只给我看代码,我想点击网站会很好。看你不能靠Scrapy自己点击,相反你可以通过某种方式获取HREF。将链接和您的尝试放在您的问题中。不过,我正在使用selenium spiders。如果只向我显示代码,我想点击网站会很好。请看,您不能通过Scrapy本身点击,相反,您可以以某种方式获取HREF。在你的问题中加入链接和你的尝试。不过我正在使用selenium Spider。