Closed liuyun16 closed 6 years ago
@liuyun16 In Zotero the field is not named author
but creators
and the entries there have a subfield creatorType
which can be author
. Try something like this:
var author = text(doc, '#meta_content em:nth-of-type(2)');
items.creators.push({
lastName: author,
fieldMode: true,
creatorType: "author"
});
The snapshot is working for me and also in your picture I see the arrow/triangle in front of the entry, which indicates that something is attached to it.
You have two times a section with tests:
/** BEGIN TEST CASES **/
...
/** END TEST CASES **/
/** BEGIN TEST CASES **/
...
/** END TEST CASES **/
This does not work. There should only be one section containing all the tests. Moreover, I see that you are first using EM translator but then scraped more or less everything from the page directly. Is the EM translator still useful here?
I am also looking forward for a PR when you have finished the translator.
@zuphilip Thx very much for your advice!
I have tried, but the author could not properly pushed. If possible, you can see the upgraded code in the WeixinSogou.js.
The good news is that I can get the snapshot now. and other fields, like title, url, rights could be scraped successfully.
As for the EM translator, I just used it for getting snapshot, because the code:
items.attachments.push({
url: items.url,
title: 'Snapshot',
mimeType: 'text/html',
snapshot: true
});
also could not get the snapshot in Chrome, even though the Scaffold shows the snapshot is OK.
By the way , I wondering the author problem may come from the the Chinese characters, So I also referred to other good translator like Douban.js, and Amazon.js. The results are that when I use the ZU.cleanAuthor()
, the Zotero connect gave errors like:
Did you restarted the browser and Zotero after you changed the code? I have to do this frequently when I test outside Scaffold.
@zuphilip theoretically "update translators" from the Connector should be all that's needed -- that doesn't work consistently for you?
@zuphilip
Yes, I have restarted the browser and Zotero every time after changing the code.
Also if there is no ZU.cleanAuthor()
, Actually the translator will not give this kind of error..
You can look at the connector debug output in the Zotero Connector preferences -- I'd suggest doing that.
My guess is that you're calling ZU.cleanAuthor()
on an empty string, which causes the error you're seeing.
First thing I'd try is to simplify the xpath (or use a CSS selector) for getting authorNames
, e.g. along the lines @zuphilip suggests above. What you currently have is very fragile and I'd guess there might just be a small difference between the page as displayed in Chrome and in Scaffold which then causes authorNames to be null.
@adam3smith I have to try this out. But sometimes I also work in old branches and may not want the update of all the other translators...
@liuyun16 I downloaded your gist and it the authors worked for my also in the browser without problems. However, I agree that you should try a more robust expression, e.g. the one I suggested above. BTW I don't think that ZU.cleanAuthor
will do anything for Chinese names.
@zuphilip Thanks!
You are right. I have changed a more expression.
var authorNames = ZU.xpathText(doc, '//*[@id="meta_content"]/em[2]');
And now the translator works properly!
Now maybe I can make a PR to share the translator.
Hello, I was just study to write a translator for a websites. I now can run the new translator in the scaffold window,
you can find the author and the snapshots should be recorded.
But when I use this translator in the Chrome, the translator could not work the same.
The fields fo snapshots and author are empty. only the url field works.
So what's the problem?
I'm quite new for javascript. So could you give me some help??