You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 305c310
Browse filesBrowse the repository at this point in the historyBrowse files
quadrinhos-digitais-parte-1-analise-do-site-para-web-scraping/), we'll now
8
+
Comixology in the [这个系列的前一篇文章](http://felipegalvao.com.br/blog/2016/05/01/comixology-analise-de-quadrinhos-digitais-parte-1-analise-do-site-para-web-scraping/), we'll now
11
9
talk about the web scraping with Python, the code itself. As we have already
12
10
talked about, we will use requests to make requests to web pages and lxml with
13
11
Xpath for parsing and information extraction from the desired pages. Let's go.
14
12
15
-
## Starting to write the code
13
+
## 开始写代码
16
14
17
15
To start the conversation, we will import the necessary libraries, requests
18
16
and, from lxml, the html function. To access the HTML parts, we will use
19
17
Xpath. So, let's talk about Xpath before we move on to the code. I'll try to
20
18
keep it short.
21
19
22
-
## Xpath: What it is and how to use it
20
+
## Xpath:它是啥,以及如何使用它
23
21
24
22
Xpath is a query language used to extract content from XML / HTML documents.
25
23
It can be used to extract information form nodes and attributes, being very
@@ -48,7 +46,7 @@ descendants. Considering the following XML code:
48
46
</store>
49
47
```
50
48
51
-
The relations are as following:
49
+
其关系如下:
52
50
53
51
* Father - Elements that contain another elements. In our example, product is the father of class, color and price.
54
52
* Children - Analogously, children are elements that are contained in another element. The class, color and price elements are children of the product element.
@@ -194,22 +192,20 @@ something that does not exist in the document, an empty list is returned.
194
192
And now that we saw this simple example, let's move on to something more
195
193
complex and fun.
196
194
197
-
## Returning to the code
195
+
## 回到代码
198
196
199
197
Now that we know what Xpath is about, let's use it to extract the Comixology
200
198
website itself. For web scraping with Xpath, one of our best friends will be
201
199
the "Inspect Element" feature from Chrome or Firefox. It will allow us to see
202
200
the source code and the HTML structure and path for a certain element in the
203
201
page.
204
202
205
-
Let's move on to the Publishers section on Comixology. ([click
206
-
here](https://www.comixology.com/browse-publisher)). We will extract our code
203
+
Let's move on to the Publishers section on Comixology. ([点击这里](https://www.comixology.com/browse-publisher)). We will extract our code
207
204
defining the function and creating an empty list which will hold the Publisher
208
205
links that we will extract. As we talked on the first post, we will define the
209
206
page quantity manually (4 pages, so, we will have a for page in range (1,5)),
210
207
and we will pass through each of them. If we go to the site and change to the
211
-
next page, we will see that the link becomes: https://www.comixology.com
212
-
/browse-publisher?publisherList_pg=2. If we change it back to the first page,
208
+
next page, we will see that the link becomes: https://www.comixology.com/browse-publisher?publisherList_pg=2. If we change it back to the first page,
213
209
the final part of the link turn back to 1. The first pages of the code will be
214
210
as following:
215
211
@@ -252,10 +248,7 @@ class "list FeaturedPublisherList", items from the All Publishers table are in
252
248
a div that has the class "list publisherList". Let's make our Xpath sentence
0 commit comments