我正在尝试访问Goodreads API that sends me information about books。我特别想获得“货架”。通过the url访问它们时,我没有问题。
<GoodreadsResponse>
...
<authors>
<author>
<id>18</id>
<name>Gary Paulsen</name>
<role/>
<image_url nophoto="false">
<![CDATA[
https://images.gr-assets.com/authors/1309159225p5/18.jpg
]]>
</image_url>
<small_image_url nophoto="false">
<![CDATA[
https://images.gr-assets.com/authors/1309159225p2/18.jpg
]]>
</small_image_url>
<link>
<![CDATA[
https://www.goodreads.com/author/show/18.Gary_Paulsen
]]>
</link>
<average_rating>3.77</average_rating>
<ratings_count>427417</ratings_count>
<text_reviews_count>30355</text_reviews_count>
</author>
</authors>
<reviews_widget>
<![CDATA[
<style> #goodreads-widget { font-family: georgia, serif; padding: 18px 0; width:565px; } #goodreads-widget h1 { font-weight:normal; font-size: 16px; border-bottom: 1px solid #BBB596; margin-bottom: 0; } #goodreads-widget a { text-decoration: none; color:#660; } iframe{ background-color: #fff; } #goodreads-widget a:hover { text-decoration: underline; } #goodreads-widget a:active { color:#660; } #gr_footer { width: 100%; border-top: 1px solid #BBB596; text-align: right; } #goodreads-widget .gr_branding{ color: #382110; font-size: 11px; text-decoration: none; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } </style> <div id="goodreads-widget"> <div id="gr_header"><h1><a rel="nofollow" href="https://www.goodreads.com/book/show/50.Hatchet">Hatchet Reviews</a></h1></div> <iframe id="the_iframe" src="https://www.goodreads.com/api/reviews_widget_iframe?did=DEVELOPER_ID&format=html&isbn=0689840926&links=660&min_rating=&review_back=fff&stars=000&text=000" width="565" height="400" frameborder="0"></iframe> <div id="gr_footer"> <a class="gr_branding" target="_blank" rel="nofollow noopener noreferrer" href="https://www.goodreads.com/book/show/50.Hatchet?utm_medium=api&utm_source=reviews_widget">Reviews from Goodreads.com</a> </div> </div>
]]>
</reviews_widget>
<popular_shelves>
<shelf name="to-read" count="42731"/>
<shelf name="currently-reading" count="4063"/>
<shelf name="young-adult" count="2452"/>
<shelf name="fiction" count="1960"/>
<shelf name="adventure" count="1052"/>
<shelf name="favorites" count="1027"/>
<shelf name="classics" count="909"/>
<shelf name="ya" count="832"/>
但是当我尝试通过代码(goodreads.py
访问它时,我只收到了一部分通过URL收到的响应。
这是goodreads.py
的代码:
#get every books from the csv file
# (in the same directory that your python process is based)
# Control delimiters, rows, column names with read_csv (see later)
data = pd.read_csv("books.csv", nrows=10)
# Preview the first 5 lines of the loaded data
print(data.head())
for i,row in data.iterrows():
res = requests.get("https://www.goodreads.com/book/isbn", params={"isbn": data['isbn'][i], "user_id": 49393496, "format":"json"})
parsed = json.loads(res.text)
print(json.dumps(parsed, indent=4))
print(data.head())
这是终端的答案:
(col_env) C:\Users\antoi\Documents\Programming\projects\collective_intelligence>python goodreads.py
isbn title author year
0 0380795272 Krondor: The Betrayal Raymond E. Feist 1998
1 1416949658 The Dark Is Rising Susan Cooper 1973
2 1857231082 The Black Unicorn Terry Brooks 1987
3 0553803700 I, Robot Isaac Asimov 1950
4 080213825X Four Blondes Candace Bushnell 2000
{'reviews_widget': '<style>\n #goodreads-widget {\n font-family: georgia, serif;\n padding: 18px 0;\n width:565px;\n }\n #goodreads-widget h1 {\n font-weight:normal;\n font-size: 16px;\n border-bottom: 1px solid #BBB596;\n margin-bottom: 0;\n }\n #goodreads-widget a {\n text-decoration: none;\n color:#660;\n }\n iframe{\n background-color: #fff;\n }\n #goodreads-widget a:hover { text-decoration: underline; }\n #goodreads-widget a:active {\n color:#660;\n }\n #gr_footer {\n width: 100%;\n border-top: 1px solid #BBB596;\n text-align: right;\n }\n #goodreads-widget .gr_branding{\n color: #382110;\n font-size: 11px;\n text-decoration: none;\n font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;\n }\n</style>\n<div id="goodreads-widget">\n <div id="gr_header"><h1><a rel="nofollow" href="https://www.goodreads.com/book/show/92918.Krondor">Krondor Reviews</a></h1></div>\n <iframe id="the_iframe" src="https://www.goodreads.com/api/reviews_widget_iframe?did=DEVELOPER_ID&format=html&isbn=0380795272&links=660&review_back=fff&stars=000&text=000" width="565" height="400" frameborder="0"></iframe>\n <div id="gr_footer">\n <a class="gr_branding" target="_blank" rel="nofollow noopener noreferrer" href="https://www.goodreads.com/book/show/92918.Krondor?utm_medium=api&utm_source=reviews_widget">Reviews from Goodreads.com</a>\n </div>\n</div>\n'}
我只有reviews_widget
。
为什么响应格式会有所不同?
如何获取应用程序的所有结果,尤其是货架?