Create a mechanism for posting reservations to Qiita [Draft acquisition] ~ Coding 10 lines a day ~ ~

8th day

Continuing from the last time, we will create the acquisition part of Qiita.

[Technical theme]

Qiita draft scraping

language

Target deliverable

Get a list of your own drafts on Qiita

Code and documentation

Implementation of draft acquisition

Since it is a login-type process like last time, use mechanize.

crawler.rb

crawler.rb


page = agent.get("https://qiita.com/drafts")
doc = Nokogiri::HTML.parse(page.body, nil, 'utf-8')
json = JSON.parse(doc.css('.js-react-on-rails-component')[1].inner_html)
json['creating_draft_items'].each do |item|
  if item['raw_body'].match(/Reservation posting/)
    id = item['item_uuid']
    title = item['title']
    raw_body = item['raw_body']
    tags = item['tag_notation'].split(' ')
    agent.get("https://qiita.com/drafts/#{id}")
    tag_data = []
    tags.each do |tag|
      tag_data.push({name:tag,versions: []})
    end
  end
end

Add the above sentence by adding & modifying from the last time. In the above code, we get a list of draft information, and if there is a word "reserved post" in it, we get that information. Last time, I specified the URL as an ID in the draft acquisition part, but it will be redirected by / drafts, so this can be done.

【next time】 I'm finally going to make a post part, but it seems to be more difficult than I thought ... Maybe I'll rely on selenium ...

Recommended Posts

Create a mechanism for posting reservations to Qiita [Draft acquisition] ~ Coding 10 lines a day ~ ~
Create a mechanism to post reservations to Qiita [Reservation posting] ~ Coding 10 lines a day ~ ~
Coding 10 lines a day ~ Scraping implementation ~
How to create a Maven repository for 2020
Coding 10 lines a day ~ Scraping environment construction ~
How to create a database for H2 Database anywhere
How to create pagination for a "kaminari" array
I want to create a generic annotation for a type
Tutorial to create a blog with Rails for beginners Part 1
How to create a lightweight container image for Java apps
Tutorial to create a blog with Rails for beginners Part 2
How to create and launch a Dockerfile for Payara Micro
Tutorial to create a blog with Rails for beginners Part 0