Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
E
esi-table-data
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esi-data-scrapping
esi-table-data
Commits
afea8191
Commit
afea8191
authored
Jun 12, 2017
by
Vasyl Bodnaruk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make spider with pagination handling by company profile
parent
8744a168
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
9 deletions
+36
-9
pipelines.py
exa/exa/pipelines.py
+2
-3
settings.py
exa/exa/settings.py
+1
-1
techcrunch.py
exa/exa/spiders/techcrunch.py
+33
-5
No files found.
exa/exa/pipelines.py
View file @
afea8191
...
@@ -19,7 +19,8 @@ class ExaPipeline(object):
...
@@ -19,7 +19,8 @@ class ExaPipeline(object):
def
process_item
(
self
,
item
,
spider
):
def
process_item
(
self
,
item
,
spider
):
item
[
'title'
]
=
''
.
join
(
item
[
'title'
])
.
replace
(
'
\n
'
,
' '
)
item
[
'title'
]
=
''
.
join
(
item
[
'title'
])
.
replace
(
'
\n
'
,
' '
)
item
[
'description'
]
=
''
.
join
(
item
[
'description'
])
.
replace
(
'
\n
'
,
' '
)
if
item
[
'description'
]:
item
[
'description'
]
=
''
.
join
(
item
[
'description'
])
.
replace
(
'
\n
'
,
' '
)
data
=
(
item
[
'title'
],
item
[
'description'
],
item
[
'url'
],
item
[
'media_id'
],
item
[
'type_id'
],
data
=
(
item
[
'title'
],
item
[
'description'
],
item
[
'url'
],
item
[
'media_id'
],
item
[
'type_id'
],
item
[
'region_id'
],
item
[
'post_id'
],
item
[
'date'
],
datetime
.
now
()
.
date
(),
item
[
'company_id'
],
0
)
item
[
'region_id'
],
item
[
'post_id'
],
item
[
'date'
],
datetime
.
now
()
.
date
(),
item
[
'company_id'
],
0
)
query
=
"""INSERT INTO wp_esi_news_accept (title, description, URL, media_id, type_id, region_id, post_id,
query
=
"""INSERT INTO wp_esi_news_accept (title, description, URL, media_id, type_id, region_id, post_id,
...
@@ -30,8 +31,6 @@ class ExaPipeline(object):
...
@@ -30,8 +31,6 @@ class ExaPipeline(object):
print
(
"UNIQUE"
,
item
)
print
(
"UNIQUE"
,
item
)
self
.
db
.
insert
(
query
,
data
)
self
.
db
.
insert
(
query
,
data
)
self
.
urls
.
add
(
item
[
'url'
])
self
.
urls
.
add
(
item
[
'url'
])
# self._insert_news_entiry(news, item['company_id'])
# self.out.write(query)
return
item
return
item
...
...
exa/exa/settings.py
View file @
afea8191
...
@@ -72,7 +72,7 @@ DOWNLOADER_MIDDLEWARES = {
...
@@ -72,7 +72,7 @@ DOWNLOADER_MIDDLEWARES = {
# Configure item pipelines
# Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES
=
{
ITEM_PIPELINES
=
{
#
'exa.pipelines.ExaPipeline': 300,
'exa.pipelines.ExaPipeline'
:
300
,
}
}
# Enable and configure the AutoThrottle extension (disabled by default)
# Enable and configure the AutoThrottle extension (disabled by default)
...
...
exa/exa/spiders/techcrunch.py
View file @
afea8191
...
@@ -17,7 +17,7 @@ class TechcrunchSpider(scrapy.Spider):
...
@@ -17,7 +17,7 @@ class TechcrunchSpider(scrapy.Spider):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
condition
=
kwargs
.
get
(
'query'
)
self
.
condition
=
kwargs
.
get
(
'query'
)
self
.
query
=
"SELECT id, name, country FROM wp_esi_entity WHERE 1 and id=
26
"
self
.
query
=
"SELECT id, name, country FROM wp_esi_entity WHERE 1 and id=
3
"
if
self
.
condition
:
if
self
.
condition
:
print
(
self
.
condition
)
print
(
self
.
condition
)
self
.
query
+=
' or {}'
.
format
(
self
.
condition
)
self
.
query
+=
' or {}'
.
format
(
self
.
condition
)
...
@@ -31,8 +31,10 @@ class TechcrunchSpider(scrapy.Spider):
...
@@ -31,8 +31,10 @@ class TechcrunchSpider(scrapy.Spider):
yield
scrapy
.
Request
(
i
.
url
+
'/'
,
callback
=
self
.
parse
,
meta
=
{
'company'
:
i
,
'post_id'
:
0
})
yield
scrapy
.
Request
(
i
.
url
+
'/'
,
callback
=
self
.
parse
,
meta
=
{
'company'
:
i
,
'post_id'
:
0
})
def
parse
(
self
,
response
):
def
parse
(
self
,
response
):
if
'tag'
in
response
.
url
:
if
'tag'
in
response
.
url
:
return
self
.
parse_tag
(
response
)
return
self
.
parse_tag
(
response
)
if
'company'
in
response
.
url
:
return
self
.
parse_company
(
response
)
def
get_common_items
(
self
,
company
):
def
get_common_items
(
self
,
company
):
return
{
'region_id'
:
company
.
region_id
,
'type_id'
:
company
.
type_id
,
return
{
'region_id'
:
company
.
region_id
,
'type_id'
:
company
.
type_id
,
...
@@ -55,11 +57,37 @@ class TechcrunchSpider(scrapy.Spider):
...
@@ -55,11 +57,37 @@ class TechcrunchSpider(scrapy.Spider):
yield
item
yield
item
has_next
=
response
.
xpath
(
"//div[contains(@class, 'river-nav')]//li[contains(@class, 'next')]/a/@href"
)
.
extract_first
()
if
has_next
:
next_url
=
'https://techcrunch.com'
+
has_next
+
'/'
yield
scrapy
.
Request
(
next_url
,
callback
=
self
.
parse_tag
,
meta
=
{
'company'
:
response
.
meta
[
'company'
],
'post_id'
:
0
})
except
BaseException
as
e
:
print
(
'We had error'
)
traceback
.
print_exc
()
def
parse_company
(
self
,
response
):
try
:
company
=
response
.
meta
[
'company'
]
news_list
=
response
.
xpath
(
".//div[contains(@class, 'block-content-topic')]"
)
for
i
in
news_list
:
item
=
ExaItem
()
item
[
'date'
]
=
i
.
xpath
(
"./div/time/@datetime"
)
.
extract_first
()
item
[
'title'
]
=
i
.
xpath
(
"./h3/a/text()"
)
.
extract_first
()
# Because we don't have description here
item
[
'description'
]
=
None
item
[
'url'
]
=
i
.
xpath
(
"./h3/a/@href"
)
.
extract_first
()
item
.
update
(
self
.
get_common_items
(
company
))
item
[
'post_id'
]
=
response
.
meta
[
'post_id'
]
if
'Crunch Report'
not
in
item
[
'title'
]:
yield
item
has_next
=
response
.
xpath
(
has_next
=
response
.
xpath
(
"//div[contains(@class, 'river-nav')]//li[contains(@class, 'next')]/a/@href"
)
.
extract_first
()
"//div[contains(@class, 'river-nav')]//li[contains(@class, 'next')]/a/@href"
)
.
extract_first
()
if
has_next
:
if
has_next
:
next_url
=
'https://techcrunch.com'
+
has_next
+
'/'
yield
scrapy
.
Request
(
has_next
,
callback
=
self
.
parse_company
,
yield
scrapy
.
Request
(
next_url
,
callback
=
self
.
parse
,
meta
=
{
'company'
:
response
.
meta
[
'company'
],
'post_id'
:
0
})
meta
=
{
'company'
:
response
.
meta
[
'company'
],
'post_id'
:
0
})
except
BaseException
as
e
:
except
BaseException
as
e
:
print
(
'We had error'
)
print
(
'We had error'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment