As of now, I export my Google documents by getting the content from this link:
https://docs.google.com/feeds/download/documents/export/Exportid=DOCUMENT_ID&exportFormat=EXPORT_FORMAT
This works fine, in fact I export my doc to an HTML format then I read from it, but there is no way to know when a page starts or ends.
Here's all the export formats I know of:
HTML, PDF, ODT, TXT, RTF and DOCX
PDF, ODT, RTF and DOCX all indicate separate pages when opened in a renderer. However, after searching for countless APIs for all formats (python-docx, PyPDF4, PyRTF etc), I have not been able to find a working way to read a Google document page by page.
Any suggestions?
You could use Apps Script with it you can take advantage of the DocumentApp where you can get PageBreaks.
You could then serve your tailored content as a web app.
Related
How to convert jmeter dashboard report to pdf
I'm unable to convert html report to pdf. plz suggest me the solution
C'mon, have you done at least basic research before asking? There are a lot of options, for example:
Print it to file, all modern browsers allow saving web content as PDF, check out How to save a webpage as a PDF
There are online solutions like https://html2pdf.com/
There are offline solutions like http://www.pdflite.com/html-to-pdf/
There is BM.Sense online results analysis service which allows saving load test report as PDF
I tried many ways none of it works for Jmeter HTML report, other way was to zip all the artifacts and send over email but, that zip files contains .js files which get blocked by Gmail Yahoo
I written small code in Selenium to take screenshot (used Ashot API) of HTML report and sending over mail as attachment. Challenge here is headless mode of browser takes improper screenshot, so if you are on windows this can be achieved but as PNG, till now nothing works for PDF.
I am trying to import data from the following website to Google Sheets. I want to import all the matches for the day.
https://www.tournamentsoftware.com/tournament/b731fdcd-a0c8-4558-9344-2a14c267ee8b/Matches
I have tried importxml and importhtml, but it seems this does not work as the website uses JavaScript. I have also tried to use Apipheny without any success.
When using Apipheny, the error message is
'Failed to fetch data - please verify your API Request: {DNS error'
Tl;Dr
Adapted from my answer to How to know if Google Sheets IMPORTDATA, IMPORTFEED, IMPORTHTML or IMPORTXML functions are able to get data from a resource hosted on a website? (also posted by me)
Please spend some time learning how to use the browsers developers tools so you will be able to identify
if the data is already included in source code of the webpage as JSON / literal JavaScript object or in another form
if the webpage is doing a GET or POST requests to retrieve the data and when those requests are done (i.e. as some point of the page parsing, or on event)
if the requests require data from cookies
Brief guide about how to use the web browser to find useful details about the webpage / data to import
Open the source code and look if the required data is included. Sometimes the data is included as JSON and added to the DOM using JavaScript. In this case it might be possible to retrieve the data by using the Google Sheets functions or URL Fetch Service from Google Apps Script.
Let say that you use Chrome. Open the Dev Tools, then look at the Elements tab. There you will see the DOM. It might be helpful to identify if the data that you want to import besides being on visible elements is included in hidden / not visible elements like <script> tags.
Look at Source, there you might be able to see the JavaScript code. It might include the data that you want to import as JavaScript object (commonly referred as JSON).
There are a lot of questions about google-sheets +web-scraping that mentions problems using importhtml and/or importxml that already have answers and even many include code (JavaScript snippets, Google Apps Script functions, etc.) that might save you to have to use an specialized web-scraping tool that has a more stepped learning curve. At the bottom of this answer there is a list of questions about using Google Sheets built-in functions, including annotations of the workaround proposed.
On Is there a way to get a single response from a text/event-stream without using event listeners? ask about using EventSource. While this can't be used on server side code, the answer show how to use the HtmlService to use it on client-side code and retrieve the result to Google Sheets.
As you already realized, the Google Sheets built-in functions importhtml(), importxml(), importdata() and importfeed() only work with static pages that do not require signing in or other forms of authentication.
When the content of a public page is created dynamically by using JavaScript, it cannot be accessed with those functions, by the other hand the website's webmaster may also purposefully have prevented web scraping.
How to identify if content is added dynamically
To check if the content is added dynamically, using Chrome,
Open the URL of the source data.
Press F12 to open Chrome Developer Tools
Press Control+Shift+P to open the Command Menu.
Start typing javascript, select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.
JavaScript will remain disabled in this tab so long as you have DevTools open.
Reload the page to see if the content that you want to import is shown, if it's shown it could be imported by using Google Sheets built-in functions, otherwise it's not possible but might be possible by using other means for doing web scraping.
According to Wikipedia,
Web scraping, web harvesting, or web data extraction is data scraping used for extracting data from websites.
Use of robots.txt to block Web crawlers
The webmasters could use robots.txt file to block access to website. In such case the result will be #N/A Could not fetch URL.
Use of User agent
The webpage could be designed to return a special a custom message instead of the data.
Below there are more details about how Google Sheets built-in "web-scraping" functions works
IMPORTDATA, IMPORTFEED, IMPORTHTML and IMPORTXML are able to get content from resources hosted on websites that are:
Publicly available. This means that the resource doesn't require authorization / to be logged in into any service to access it.
The content is "static". This mean that if you open the resource using the view source code option of modern web browsers it will be displayed as plain text.
NOTE: The Chrome's Inspect tool shows the parsed DOM; in other works the actual structure/content of the web page which could be dynamically modified by JavaScript code or browser extensions/plugins.
The content has the appropriated structure.
IMPORTDATA works with structured content as csv or tsv doesn't matter of the file extension of the resource.
IMPORTFEED works with marked up content as ATOM/RSS
IMPORTHTML works with marked up content as HTML that includes properly markedup list or tables.
IMPORTXML works with marked up content as XML or any of its variants like XHTML.
The content doesn't exceeds the maximum size. Google haven't disclosed this limit but the below error will be shown when the content exceeds the maximum size:
Resource at url contents exceeded maximum size.
Google servers are not blocked by means of robots.txt or the user agent.
On W3C Markup Validator there are several tools to checkout is the resources had been properly marked up.
Regarding CSV check out Are there known services to validate CSV files
It's worth to note that the spreadsheet
should have enough room for the imported content; Google Sheets has a 10 million cell limit by spreadsheet, according to this post a columns limit of 18278, and a 50 thousand characters as cell content even as a value or formula.
it doesn't handle well large in-cell content; the "limit" depends on the user screen size and resolution as now it's possible to zoom in/out.
References
https://developers.google.com/web/tools/chrome-devtools/javascript/disable
https://en.wikipedia.org/wiki/Web_scraping
Related
Using Google Apps Script to scrape Dynamic Web Pages
Scraping data from website using vba
Block Website Scraping by Google Docs
Is there a way to get a single response from a text/event-stream without using event listeners?
Software Recommendations
Web scraping tool/software available for free?
Recommendations for web scraping tools that require minimal installation
Web Applications
The following question is about a different result, #N/A Could not fetch URL
Inability to use IMPORTHTML in Google sheets
Similar questions
Some of this questions might be closed as duplicate of this one
Importing javascript table into Google Docs spreadsheet
Importxml Imported Content Empty
scrape table using google app scripts
One answer includes Google Apps Script code using the URL Fetch Service
Capture element using ImportXML with XPath
How to import Javascript tables into Google spreadsheet?
Scrape the current share price data from the ASX
One of the answers includes Google Apps Script code to get data from a JSON source
Guidance on webscraping using Google Sheets
How to Scrape data from Indiegogo.com in google sheets via IMPORTXML formula
Why importxml and importhtml not working here?
Google Sheet use Importxml error could not fetch url
One answer includes Google Apps Script code using the URL Fetch Service
Google Sheets - Pull Data for investment portfolio
Extracting value from API/Webpage
IMPORTXML shows an error while scraping data from website
One answer shows the xhr request found using browser developer tools
Replacing =ImportHTML with URLFetchApp
One answer includes Google Apps Script code using the URL Fetch Service
How to use IMPORTXML to import hidden div tag?
Google Sheet Web-scraping ImportXml Xpath on Yahoo Finance doesn't works with french stock
One of the answers includes Google Apps Script code to get data from a JSON source. As of January 4th 2023, it's not longer working, very likely because Yahoo! Finance is now encrying the JSON. See the Tainake's answer to How to pull Yahoo Finance Historical Price Data from its Object with Google Apps Script? for script using Crypto.js to handle this.
How to fetch data which is loaded by the ajax (asynchronous) method after the web page has already been loaded using apps script?
One answer suggest to read the data from the server instead of scraping from a webpage.
Using ImportXML to pull data
Extracting data from web page using Cheerio Library
One answer suggest the use of an API and Google Apps Script
ImportXML is good for basic tasks, but it won't get you too far if you are serious in scraping:
The approach only works with the most basic websites (no SPAs rendered in browsers can be scraped this way. Any basic web scraping protection or connectivity issue breaks the process, and there isn't any control over HTTP request geo location, or number of retries) - and Yahoo Finance is not a simple website
If the target website data requires some cleanup post-processing, it's getting very complicated since you are now "programming with Excel formulas", rather a painful process compared to regular code writing in conventional programming languages
There isn't any proper launch and cache control, so the function can be triggered occasionally and if the HTTP request fails, cells will be populated with ERR! values
I recommend using proper tools (automation framework and scraping engine which can render JavaScript-powered websites) and use Google Sheets just for basic storage purposes:
https://youtu.be/uBC752CWTew (Pipedream for automation and ScrapeNinja engine for scraping)
I am planning to start a blog so I created my own laravel website. My posts are markdown files with .md extension. When a user visits a post eg. example.com/how-to-create-a-webiste then my markdown file is fetched and parsed to generate html content and displayed on the view called post.
So actually I do not have any html files except for post.blade.php. So will this affect the crawler from crawling my website as I do not have html pages rather all my pages are markdown files?
The answer is NO, Google or any other SE crawler will read the compiled version of your HTML, not your markdown files.
Google offers a tool to simulate crawling and even index manually your page, you will need to sign up in Search Console, check it out here.
You have to be careful with dynamic content tho, if the time it takes to inject it in the DOM is too high the robot may leave before the content shows up.
There are experiments, to test this theory, one that suits your situations is Asynchronous injection:
Experiment
After a time out of 1000 milliseconds, the test writes a string into a DIV element.
Test content
For the test to be succesful, the following content should get indexed.
Asynchronously injected content can be found in Google search, and this is proof: ngwzjcrnub
Result
Google definitely indexes this content.
Source of the experiment
Hope this helps you.
Is there a possible way of getting Excel to import a picture into a worksheet from a web location where the web location is not a simple url to a file but a dynamic page that generates the picture from the information supplied in the url?
I'm using the shapes.addpicture method at the moment and I get error 1004 - file not found. It works with: http://www.andyross.net/images/heide_hut.jpg
But it doesn't work with:
http://charts.moneyam.com/Chart.aspx?Provider=EODIntra&Code=RBS&Size=900&Skin=GreenRed&Type=3&Scale=0&Cycle=DAY1&Span=MONTH3&OVER=EMA%2812%29;EMA%2826%29;SR;AreaBB%2826,2%29&IND=MACD%2826,12,9%29;SlowSTO%2812,3,3%29;ADX%2812%29;VOLMA%2812%29&Layout=2Line;Default;Price;HisDate&XCycle=&XFormat=
The above URL would work if I put it in the browser address bar, and would produce a gif image of the stock chart for RBS.
At first I thought it was the long file name, so I used Tinyurl to produce a url short enough to be acceptable to Excel. However, it still doesn't work (and using tinyurl for the simple url does work in excel) so I think it must be the dynamic content.
Does anyone have any thoughts on how to get this to work?
You'd probably be better off using an embedded webbrowser control. This video can step you through setting it up and using it http://www.youtube.com/watch?v=GBAHJSfm8Xg
I have a website that displays product information that the client wishes to offer as pdf format. I need a way to dynamically convert a particular HTML page into a PDF, does anybody know of a way to do this? I need to convert an html page into a PDF document and serve it to the end user on the fly (there are WAY too many products to do this manually and these products receive updates regularly so a manual approach is out of the question)
EDIT: I forgot to mention that I need this to use either vb.net or c#.net
Have you tried iTextSharp?