The stock research report rating information can reflect the changes in the views of brokerage analysts on stock fundamentals and can be used as a certain reference.
Oriental Wealth Online updates the rating information of a large number of stocks on a daily basis. How can you crawl it all down with a program?
Enter the prompt word in ChatGPT:
You are a Python programming expert, to complete the task of crawling web table data, the specific steps are as follows:
Open the website with pyperteer: https://data.eastmoney.com/report/stock.jshtml;
Cyclic page turning: locate the input input box of id="gotopageindex", then use the clear() method to clear the input box, and then fill in the corresponding page number {pagenumber} through the send_keys() method, the value of pagenumber is from 1 to 100, and then locate the input element of value="Go", click;
Wait 10 seconds for the page to load out of the table;
Create a table under the folder "Stock Research Report Rating" in the F drive: 1 .xlsx;
The td content of Xpath=//*[@id="stock_table"]/table/tbody/tr[{rowno}]/td[{cono}] is written to column {cono} of 1.xlsx, where rowno's value is from 1 to 50 and cono's value is from 1 to 15;
Then open all the tables under the F drive folder "Stock Research Report Rating", delete the first row of all the tables, and then merge all the tables into one table file according to the table title name smoothly: stock.xlsx
Note: Some data in the second column is: 002739, these are characters, and all the 0s at the beginning of the merge process should be kept
Note: Each step outputs information
After the program runs, an error occurs, submit an error message to ChatGPT, and modify it
Run again, extract the data correctly:
All stock rating information has been saved to excel sheets: