├── .github └── workflows │ ├── codeql-analysis.yml │ └── python-app.yml ├── .gitignore ├── Code.txt ├── LICENSE ├── README.md ├── main.py ├── requirements.txt └── src ├── Baidu_upload.py ├── CCTV_News.py ├── East_Finance.py ├── Fh_Finance.py ├── Jrj_Finance.py ├── Platform.py ├── Self_Stock.py ├── Sg_Finance.py ├── Sina_Finance.py ├── Ths_Finance.py ├── Tzj_Finance.py ├── UA.py ├── Wy_Finance.py ├── Xhs_Finance.py ├── Xq_Community.py └── search_us.py /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '34 16 * * 3' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'python' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: newsci 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up Python 3.9 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: 3.9 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | pip install flake8 pytest 27 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 28 | - name: hello 29 | run: echo Hello, github action 30 | 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /Code.txt: -------------------------------------------------------------------------------- 1 | #请按照以下格式输入 股票代码(全号)#名字 2 | #例: SH600887#伊利 SH600887是股票代码 #号后的"伊利"是给表格分类命名 3 | SH600900#长江电力 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # News-M 2 | 3 | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/VcSpace/News-M/python-app.yml?branch=main) 4 | ![https://img.shields.io/badge/platform-Linux--64%20%7C%20Macosx%20%7C%20Win--64-blue](https://img.shields.io/badge/platform-Linux%20%7C%20Macos%20%7C%20Windows-blue) ![https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7-blue](https://img.shields.io/badge/python-v3-blue) ![https://img.shields.io/github/license/VcSpace/News-M?color=blue](https://img.shields.io/github/license/VcSpace/News-M?color=blue) ![https://img.shields.io/github/stars/VcSpace/News-M?style=social](https://img.shields.io/github/stars/VcSpace/News-M?style=social) 5 | 6 | --- 7 | 8 | ## 数据来源 | Data 9 | 10 | **网易财经、同花顺财经、金融界财经、凤凰财经、东方财富、新浪财经、新华网财经、松果财经、新闻联播文字版、投资界。** 11 | 12 | **NetEase Finance and economics, flush finance and economics, finance and economics in financial circles, Phoenix finance and economics, Oriental Fortune, sina finance and economics, Xinhuanet finance and economics, pinecone finance and economics, news broadcast text version and investment circles. The data will be generated into tables and stored in the finance folder** 13 | 14 | --- 15 | 16 | ## 运行程序 | Run 17 | 18 | ```python 19 | #Run 20 | #新闻联播文字版、个股处理功能、网盘资料备份默认关闭,自行开启。 21 | pip install -r requirements.txt 22 | python3 main.py 23 | ``` 24 | 25 | > [!IMPORTANT] 26 | > Windows新闻文件生成在桌面, Linux/Macos生成在运行目录下 27 | 28 | Windows system is generated on the desktop, Linux/Macos is generated in the running directory 29 | 30 | **使用教程 | Tutorial: [https://6923403.github.io/post/news_wps](https://vcvvvc.github.io/post/news_wps)** 31 | 32 | - 更多设置, 请查看教程 33 | 34 | - More settings, check out the tutorial 35 | 36 | --- 37 | 38 | ## 跨平台 | Cross-Plateform 39 | 40 | **实机测试:** 41 | 42 | **Running in real environment** 43 | 44 | - **Windows7 + python3.7** 45 | 46 | - **Ubuntu20.04 + python3.8** 47 | 48 | - **Macos11.4 + python3.9** 49 | 50 | --- 51 | 52 | ## 关于 | About 53 | 54 | **提取财经新闻标题、链接进行整合排列写入表格,省去繁琐步骤, 提高效率。过去每日会大约花费一小时时间用来获取新闻资讯,效率极低,目前10分钟即可全部阅完。** 55 | 56 | **Extracting the financial news headlines and links for integration and arrangement and writing them into the table eliminates the complicated steps of searching the website, opening the web page, viewing the title, opening the web page, closing the web page and continuing to view the next one. In the past, it took one hour to get up early to watch the news, but now it can be done in 10 minutes.** 57 | 58 | 59 | --- 60 | 61 | ## 开源协议 | License 62 | 63 | ``GPLV3 License`` 64 | 65 | --- 66 | 67 | ## Stargazers over time 68 | 69 | [![Stargazers over time](https://starchart.cc/VcSpace/News-M.svg)](https://starchart.cc/VcSpace/News-M) 70 | 71 | 72 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time 3 | import logging 4 | import random 5 | import os 6 | 7 | from src.Platform import pt 8 | from src.Wy_Finance import Wy 9 | from src.Ths_Finance import Ths 10 | from src.Jrj_Finance import Jrj 11 | from src.Fh_Finance import Fh 12 | from src.East_Finance import Ew 13 | from src.Self_Stock import Stock 14 | from src.CCTV_News import CCTV 15 | from src.Sina_Finance import Sina 16 | from src.Xhs_Finance import Xhs 17 | from src.Sg_Finance import Sg 18 | from src.Tzj_Finance import Tzj 19 | import src.Baidu_upload 20 | 21 | def get_News(platform, filename, debug): 22 | #debug True开启 23 | if debug: 24 | Wy.create_file(filename) 25 | CCTV.main() 26 | return 27 | Wy.main(filename) 28 | # t1 = threading.Thread(target=CCTV.main, args=()) #新闻联播文字版获取默认关闭,经常失效,失效后不再更新 29 | # t2 = threading.Thread(target=Stock.main, args=(filename,)) #个股处理版本默认关闭,使用先在Code.txt添加代码+名称,失效不再更新 30 | # t1.start() 31 | # t2.start() 32 | Xhs.main(filename) 33 | Ths.main(filename) 34 | Jrj.main(filename) 35 | # Fh.main(filename)#接口失效 36 | Ew.main(filename) 37 | Sina.main(filename) 38 | Tzj.main(filename) 39 | Sg.main(filename) 40 | # t1.join() 41 | # t2.join() 42 | 43 | def get_filename(platform): 44 | if platform == True: 45 | win_file = pt.win_filename() 46 | return win_file 47 | else: 48 | linux_file = pt.linux_filename() 49 | return linux_file 50 | 51 | if __name__ == '__main__': 52 | Debug = False 53 | m_platform = pt.get_platform() #判断系统 54 | filename = get_filename(m_platform) 55 | get_News(m_platform, filename, Debug) #获取信息 56 | 57 | pt.file_move(m_platform) #文件移动 重命名操作 58 | 59 | """ 60 | 授权步骤 61 | 命令行bypy info || python -m bypy info || python3 -m bypy info 62 | 打开链接-登陆-授权 63 | 复制授权码 64 | 粘贴到命令行-enter 65 | """ 66 | bd_flag = False #改为True开启 67 | if bd_flag == False or Debug == True: 68 | print("如果需要上传到云盘备份 请自行开启bd.main \n") 69 | else: 70 | Bd = src.Baidu_upload.Baidu() 71 | Bd.main() 72 | 73 | print("操作完成") 74 | 75 | if m_platform == True: 76 | pt.pause() 77 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.25.1 2 | openpyxl==3.0.6 3 | beautifulsoup4==4.11.2 4 | lxml==4.9.2 5 | bypy==1.7.12 6 | wget==3.2 -------------------------------------------------------------------------------- /src/Baidu_upload.py: -------------------------------------------------------------------------------- 1 | import os 2 | from src.Platform import pt 3 | from bypy import ByPy 4 | 5 | class Baidu(object): 6 | def __init__(self): 7 | bp = ByPy() 8 | #print(bp.info()) # or whatever instance methods of ByPy class 9 | # 使用上传接口之前,请申请接入,申请地址为:https://pan.baidu.com/union/apply/ 10 | 11 | # def get_token(self): 12 | # #用不到 13 | # url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id={0}&client_secret={1}".format(self.AppKey, self.SecretKey) 14 | # # 获取token 15 | # res = requests.get(url).text 16 | # data = json.loads(res) # 将json格式转换为字典格式 17 | # self.access_token = data['access_token'] 18 | # self.filename = pt.filename() 19 | 20 | def upload(self): 21 | path = pt.getpath() 22 | print("正在同步备份文件,如果文件过多 请耐心等待") 23 | #re: https://www.jianshu.com/p/19ddb60e2b22 24 | cmd = 'bypy syncup ' + path + " /" 25 | try: 26 | print("上传完成: ", os.system(cmd)) 27 | except: 28 | print("上传出错") 29 | 30 | def main(self): 31 | self.upload() #bypy 把当前目录同步到云盘 -------------------------------------------------------------------------------- /src/CCTV_News.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | import os 4 | import shutil 5 | from src.Platform import pt 6 | import time 7 | 8 | """ 9 | http://mrxwlb.com/category/mrxwlb-text/amp/ 10 | cn.govopendata.com 11 | http://www.11417.cn/cctv.html 12 | """ 13 | 14 | headers = { 15 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 16 | } 17 | 18 | class CCTV_News(object): 19 | def __init__(self): 20 | pass 21 | 22 | def request(self): 23 | newslist = '' 24 | url = 'http://mrxwlb.com/category/mrxwlb-text/amp/' 25 | data = '' 26 | for ll in range(3): 27 | try: 28 | data = requests.get(url, headers=headers, timeout=120) 29 | if data.status_code == 200: 30 | break 31 | except Exception as e: 32 | pass 33 | 34 | self.soup = BeautifulSoup(data.text, "lxml") 35 | m_new = self.soup.find(class_='loop-title') 36 | m_url = m_new.find('a') 37 | self.mr_url = m_url['href'] 38 | self.mr_title = m_url.get_text() 39 | 40 | 41 | def getNews(self): 42 | news = '' 43 | # self.mr_url = 'http://mrxwlb.com/2022年2月15日新闻联播文字版/amp/' 44 | # self.mr_title = '2022年2月15日新闻联播文字版' 45 | for _ in range(10): 46 | try: 47 | news = requests.get(self.mr_url, headers=headers) 48 | break 49 | except: 50 | continue 51 | soup = BeautifulSoup(news.text, "lxml") 52 | content = soup.find_all(class_='cntn-wrp artl-cnt') 53 | # 补全 54 | self.filename = self.mr_title + ".md" 55 | with open(self.filename, "w+", encoding='utf-8') as f: 56 | for news in content: 57 | m_con = news.find_all('li') 58 | m_con2 = news.find_all('p') 59 | for m_cont in m_con: 60 | m_content = m_cont.get_text() 61 | f.write("- " + m_content + "\n") 62 | f.write("---" + "\n") 63 | for m_cont in m_con2: 64 | m_content = m_cont.get_text() 65 | f.write("- " + m_content + "\n") 66 | 67 | if pt.get_platform() == True: 68 | self.win_cctv_file(self.filename) 69 | else: 70 | self.lin_cctv_file(self.filename) 71 | 72 | 73 | def getfilename(self): 74 | return self.filename 75 | 76 | def lin_cctv_file(self, filename): 77 | path = "./Finance/CCTV_News/" 78 | isExists = os.path.exists(path) 79 | if not isExists: 80 | os.mkdir(path) 81 | shutil.move(filename, path + filename) 82 | 83 | def win_cctv_file(self, cctv_file): 84 | desktop_path = os.path.join(os.path.expanduser('~'),"Desktop") #获取桌面路径 85 | path = desktop_path +"\\Finance\\CCTV_News\\" 86 | isExists = os.path.exists(path) 87 | if not isExists: 88 | os.mkdir(path) 89 | 90 | shutil.move(cctv_file, path + cctv_file) 91 | 92 | def request_114(self): 93 | newslist = '' 94 | url = 'http://www.11417.cn/cctv.html' 95 | for _ in range(10): 96 | try: 97 | newslist = requests.get(url, headers=headers, timeout=30) 98 | break 99 | except: 100 | continue 101 | self.soup = BeautifulSoup(newslist.text, "lxml") 102 | m_new = self.soup.select('#hcsticky > div.content > div.block > div:nth-child(1) > h2 > a') 103 | self.m114_url = m_new[0]['href'] 104 | self.m114_title = m_new[0].get_text() 105 | 106 | 107 | def getNews_114(self): 108 | news = '' 109 | # self.m_url = 'http://www.11417.cn/7309.html' 110 | # self.m_title = '2022年01月06日新闻联播文字版完整版' 111 | for _ in range(10): 112 | try: 113 | news = requests.get(self.m114_url, headers=headers, timeout=30) 114 | break 115 | except: 116 | continue 117 | 118 | soup = BeautifulSoup(news.text, "lxml") 119 | content = soup.find_all(class_='single') 120 | 121 | self.filename = self.m114_title + ".md" 122 | with open(self.filename, "w+", encoding='utf-8') as f: 123 | for news in content: 124 | #m_con = news.find_all('li') 125 | m_con2 = news.find_all('p') 126 | for m_cont in m_con2: 127 | m_content = m_cont.get_text() 128 | f.write("- " + m_content + "\n") 129 | 130 | if pt.get_platform() == True: 131 | self.win_cctv_file(self.filename) 132 | else: 133 | self.lin_cctv_file(self.filename) 134 | 135 | 136 | def main(self): 137 | #获取今天与昨天的新闻联播 已获取会自动覆盖 138 | CCTV.request() 139 | CCTV.getNews() 140 | # CCTV.request_114() 141 | # CCTV.getNews_114() 142 | 143 | 144 | CCTV = CCTV_News() 145 | -------------------------------------------------------------------------------- /src/East_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | from openpyxl.styles import Font 5 | import json 6 | import time 7 | import threading 8 | 9 | headers = { 10 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 11 | } 12 | 13 | class EastWealth(object): 14 | def __init__(self): 15 | pass 16 | 17 | def request(self): 18 | self.url = 'https://www.eastmoney.com/' 19 | 20 | for ll in range(3): 21 | try: 22 | self.data = requests.get(self.url, headers=headers, timeout=120) 23 | if self.data.status_code == 200: 24 | break 25 | except Exception as e: 26 | pass 27 | self.data.encoding = "utf-8" 28 | self.soup = BeautifulSoup(self.data.text, "lxml") 29 | 30 | self.stock_url = 'http://stock.eastmoney.com/' 31 | 32 | for ll in range(3): 33 | try: 34 | self.stock_data = requests.get(self.stock_url, headers=headers, timeout=120) 35 | if self.stock_data.status_code == 200: 36 | break 37 | except Exception as e: 38 | pass 39 | self.stock_data.encoding = "utf-8" 40 | self.stock_soup = BeautifulSoup(self.stock_data.text, "lxml") 41 | 42 | self.finance_url = 'http://finance.eastmoney.com/' 43 | 44 | for ll in range(3): 45 | try: 46 | self.finance_data = requests.get(self.finance_url, headers=headers, timeout=120) 47 | if self.finance_data.status_code == 200: 48 | break 49 | except Exception as e: 50 | pass 51 | self.finance_data.encoding = "utf-8" 52 | self.finance_soup = BeautifulSoup(self.finance_data.text, "lxml") 53 | 54 | 55 | def getTopNew(self): 56 | wb = load_workbook(self.xlsxname) 57 | sheet = wb.create_sheet("Ew") 58 | t_row = 1 59 | t_col = 1 60 | sheet.cell(row=t_row, column=t_col, value="东方财富") 61 | t_row = t_row + 1 62 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 63 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 64 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 65 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 66 | t_row = t_row + 1 67 | 68 | datalist = self.soup.find_all(class_='nlist') 69 | for Newslist in datalist: 70 | News = Newslist.find_all('a') 71 | for m_new in News: 72 | m_title = m_new.get_text() 73 | if len(m_title) <= 3: 74 | continue 75 | m_href = m_new['href'] 76 | sheet.cell(row=t_row, column=t_col, value=m_title) 77 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 78 | t_row = t_row + 1 79 | try: 80 | wb.save(self.xlsxname) 81 | except: 82 | print("EastWealth Save Error = getTopNew") 83 | 84 | 85 | def getStockNew(self): 86 | wb = load_workbook(self.xlsxname) 87 | sheet = wb.get_sheet_by_name("Ew") 88 | t_row = sheet.max_row + 2 89 | t_col = 1 90 | sheet.cell(row=t_row, column=t_col, value="股市聚焦") 91 | t_row = t_row + 1 92 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 93 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 94 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 95 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 96 | t_row = t_row + 1 97 | 98 | datalist = self.stock_soup.find_all(class_='card_body pt0 card_gsjj') 99 | for Newslist in datalist: 100 | News = Newslist.find_all('a') 101 | for m_new in News: 102 | m_title = m_new.get_text() 103 | if len(m_title) <= 3: 104 | continue 105 | m_href = m_new['href'] 106 | sheet.cell(row=t_row, column=t_col, value=m_title) 107 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 108 | t_row = t_row + 1 109 | try: 110 | wb.save(self.xlsxname) 111 | except: 112 | print("EastWealth Save Error = getStockNew") 113 | 114 | 115 | def getIndexanalysis(self): #大盘分析 116 | wb = load_workbook(self.xlsxname) 117 | sheet = wb.get_sheet_by_name("Ew") 118 | t_row = sheet.max_row + 2 119 | t_col = 1 120 | sheet.cell(row=t_row, column=t_col, value="主力市场") 121 | t_row = t_row + 1 122 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 123 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 124 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 125 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 126 | t_row = t_row + 1 127 | 128 | datalist = self.stock_soup.find_all(class_='list list-md list-truncate') 129 | datalist2 = self.stock_soup.find_all(class_='card_body pt0 common_list') 130 | for Newslist in datalist: 131 | News = Newslist.find_all('a') 132 | for m_new in News: 133 | m_title = m_new.get_text() 134 | if len(m_title) <= 3: 135 | continue 136 | m_href = m_new['href'] 137 | sheet.cell(row=t_row, column=t_col, value=m_title) 138 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 139 | t_row = t_row + 1 140 | 141 | for Newslist2 in datalist2: 142 | News = Newslist2.find_all('a') 143 | for m_new in News: 144 | m_title = m_new.get_text() 145 | if len(m_title) <= 3: 146 | continue 147 | m_href = m_new['href'] 148 | sheet.cell(row=t_row, column=t_col, value=m_title) 149 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 150 | t_row = t_row + 1 151 | 152 | try: 153 | wb.save(self.xlsxname) 154 | except: 155 | print("EastWealth Save Error = Indexanalysis") 156 | 157 | 158 | def getMainNews(self): 159 | wb = load_workbook(self.xlsxname) 160 | sheet = wb.get_sheet_by_name("Ew") 161 | t_row = sheet.max_row + 2 162 | t_col = 1 163 | sheet.cell(row=t_row, column=t_col, value="财经要闻") 164 | t_row = t_row + 1 165 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 166 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 167 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 168 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 169 | t_row = t_row + 1 170 | 171 | datalist = self.finance_soup.find_all(class_='yaowen panel') 172 | for Newslist in datalist: 173 | News = Newslist.find_all('a') 174 | for m_new in News: 175 | m_title = m_new.get_text() 176 | m_href = m_new['href'] 177 | sheet.cell(row=t_row, column=t_col, value=m_title) 178 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 179 | t_row = t_row + 1 180 | try: 181 | wb.save(self.xlsxname) 182 | except: 183 | print("EastWealth Save Error = MainNews") 184 | 185 | 186 | def getFinanceNews(self): 187 | wb = load_workbook(self.xlsxname) 188 | sheet = wb.get_sheet_by_name("Ew") 189 | t_row = sheet.max_row + 2 190 | t_col = 1 191 | sheet.cell(row=t_row, column=t_col, value="财经导读") 192 | t_row = t_row + 1 193 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 194 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 195 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 196 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 197 | t_row = t_row + 1 198 | 199 | datalist = self.finance_soup.find_all(class_='daodu panel') 200 | for Newslist in datalist: 201 | News = Newslist.find_all('a') 202 | for m_new in News: 203 | m_title = m_new.get_text() 204 | if len(m_title) <= 4: 205 | continue 206 | m_href = m_new['href'] 207 | sheet.cell(row=t_row, column=t_col, value=m_title) 208 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 209 | t_row = t_row + 1 210 | try: 211 | wb.save(self.xlsxname) 212 | except: 213 | print("EastWealth Save Error = FinanceNews") 214 | 215 | 216 | def main(self, file_name): 217 | self.xlsxname = file_name 218 | Ew.request() 219 | Ew.getTopNew() 220 | Ew.getMainNews() 221 | Ew.getFinanceNews() 222 | Ew.getStockNew() 223 | Ew.getIndexanalysis() #大盘分析 224 | 225 | Ew = EastWealth() 226 | -------------------------------------------------------------------------------- /src/Fh_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook, Workbook 4 | from openpyxl.styles import Font 5 | import re 6 | import json 7 | import time 8 | 9 | """ 10 | https://tech.ifeng.com/24h/ 11 | http://tech.ifeng.com/ 12 | http://finance.ifeng.com/ 13 | """ 14 | 15 | headers = { 16 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 17 | } 18 | 19 | class FengHuang(object): 20 | def __init__(self): 21 | pass 22 | 23 | def request(self): 24 | #new 25 | self.url = 'http://finance.ifeng.com/' 26 | 27 | for ll in range(3): 28 | try: 29 | self.data = requests.get(self.url, headers=headers, timeout=120) 30 | if self.data.status_code == 200: 31 | break 32 | except Exception as e: 33 | pass 34 | 35 | self.soup = BeautifulSoup(self.data.text, "lxml") 36 | 37 | self.stock_url = 'http://finance.ifeng.com/stock/' 38 | self.stock_data = requests.get(self.stock_url, headers=headers) 39 | self.stock_soup = BeautifulSoup(self.stock_data.text, "lxml") 40 | 41 | 42 | def getTopNew(self): 43 | wb = load_workbook(self.xlsxname) 44 | sheet = wb.create_sheet("Fh") 45 | t_row = 1 46 | t_col = 1 47 | sheet.cell(row=t_row, column=t_col, value="凤凰财经") 48 | t_row = t_row + 1 49 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 50 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 51 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 52 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 53 | t_row = t_row + 1 54 | 55 | #datalist = self.soup.find_all(class_='hot-1NJ2DKa4 clearfix') 56 | datalist = self.soup.select('#root > div > div.col-3u4gcc0Q.clearfix > div.col_L-3c5atSII > div.box-1bAs3EGr') 57 | 58 | for Newslist in datalist: 59 | News = Newslist.find_all('a') 60 | for m_new in News: 61 | m_title = m_new['title'] 62 | m_href = m_new['href'] 63 | sheet.cell(row=t_row, column=t_col, value=m_title) 64 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 65 | t_row = t_row + 1 66 | try: 67 | wb.save(self.xlsxname) 68 | except: 69 | print("FengHuang Save Error = getTopNew") 70 | 71 | 72 | def stockNewslist(self, json_str, t_row): #stockNewsList 73 | wb = load_workbook(self.xlsxname) 74 | sheet = wb.get_sheet_by_name("Fh") 75 | Newslist = json_str['stockNewsList'] 76 | t_col = 1 77 | temp = 0 78 | for m_new in Newslist: 79 | temp = temp + 1 80 | if temp == 6: 81 | temp = 0 82 | t_row = t_row + 1 83 | else: 84 | m_title = m_new['title'] 85 | m_time = m_new['newsTime'] 86 | m_href = m_new['url'] 87 | sheet.cell(row=t_row, column=t_col, value=m_title) 88 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 89 | sheet.cell(row=t_row, column=t_col + 3, value=m_time) 90 | t_row = t_row + 1 91 | try: 92 | wb.save(self.xlsxname) 93 | except: 94 | print("FengHuang Save Error = getNewsList") 95 | 96 | 97 | def CompanyNews(self, json_str): #stockNewsList 没有top 只有top下的5条 98 | wb = load_workbook(self.xlsxname) 99 | sheet = wb.get_sheet_by_name("Fh") 100 | t_row = sheet.max_row + 2 101 | t_col = 1 102 | sheet.cell(row=t_row, column=t_col, value="公司要闻") 103 | t_row = t_row + 1 104 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 105 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 106 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 107 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 108 | t_row = t_row + 1 109 | 110 | CNews = json_str['news'] 111 | m_CNews = json_str['newsList'] 112 | for m_new in CNews: 113 | m_href = m_new['url'] 114 | m_title = m_new['title'] 115 | m_href = m_href.replace("//", "https://") 116 | sheet.cell(row=t_row, column=t_col, value=m_title) 117 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 118 | t_row = t_row + 1 119 | break 120 | 121 | for m_new in m_CNews: 122 | m_time = m_new['newsTime'] 123 | m_href = m_new['url'] 124 | m_title = m_new['title'] 125 | sheet.cell(row=t_row, column=t_col, value=m_title) 126 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 127 | sheet.cell(row=t_row, column=t_col + 2, value=m_time) 128 | t_row = t_row + 1 129 | try: 130 | wb.save(self.xlsxname) 131 | except: 132 | print("FengHuang Save Error = CompanyNews2") 133 | 134 | def marketAnalysis(self, json_str): 135 | wb = load_workbook(self.xlsxname) 136 | sheet = wb.get_sheet_by_name("Fh") 137 | t_row = sheet.max_row + 2 138 | t_col = 1 139 | sheet.cell(row=t_row, column=t_col, value="操盘分析") 140 | t_row = t_row + 1 141 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 142 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 143 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 144 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 145 | t_row = t_row + 1 146 | 147 | Newslist = json_str['marketAnalysis'] 148 | for m_news in Newslist: 149 | m_href = m_news['url'] 150 | m_title = m_news['title'] 151 | m_href = m_href.replace("//", "https://") 152 | sheet.cell(row=t_row, column=t_col, value=m_title) 153 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 154 | t_row = t_row + 1 155 | try: 156 | wb.save(self.xlsxname) 157 | except: 158 | print("FengHuang Save Error = marketAnalysis") 159 | 160 | 161 | def IPOObservation(self, json_str): #stockNewsList 没有top 只有top下的5条 162 | wb = load_workbook(self.xlsxname) 163 | sheet = wb.get_sheet_by_name("Fh") 164 | t_row = sheet.max_row + 2 165 | t_col = 1 166 | 167 | sheet.cell(row=t_row, column=t_col, value="IPO观察") 168 | t_row = t_row + 1 169 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 170 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 171 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 172 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 173 | t_row = t_row + 1 174 | 175 | NewsList = json_str['hotPlate'] 176 | for m_new in NewsList: 177 | m_href = m_new['url'] 178 | m_title = m_new['title'] 179 | m_href = m_href.replace("//", "https://") 180 | sheet.cell(row=t_row, column=t_col, value=m_title) 181 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 182 | t_row = t_row + 1 183 | try: 184 | wb.save(self.xlsxname) 185 | except: 186 | print("FengHuang Save Error = IPOObservation") 187 | 188 | 189 | def getStockNews(self): 190 | wb = load_workbook(self.xlsxname) 191 | sheet = wb.get_sheet_by_name("Fh") 192 | t_row = sheet.max_row + 2 193 | t_col = 1 194 | sheet.cell(row=t_row, column=t_col, value="证券要闻") 195 | t_row = t_row + 1 196 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 197 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 198 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 199 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 200 | t_row = t_row + 1 201 | soup = str(self.stock_soup) 202 | 203 | #sear = re.search(r'var allData = (.*?) .*\"\}\}\;', soup, re.M | re.I) 204 | sear = re.search('var allData = (.*?)var adData', soup, re.M | re.I | re.S) 205 | data = sear.group(1) 206 | data = data.replace(";", "") 207 | json_str = json.loads(data) 208 | #print(data) 209 | m_row = t_row + 1 210 | stockNews = json_str['stockNews'] #top新闻 211 | for m_new in stockNews: 212 | m_title = m_new['title'] 213 | href = m_new['url'] 214 | m_href = href.replace("//", "https://") 215 | sheet.cell(row=t_row, column=t_col, value=m_title) 216 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 217 | t_row = t_row + 1 218 | 219 | try: 220 | wb.save(self.xlsxname) 221 | except: 222 | print("FengHuang Save Error = getStockNews") 223 | 224 | self.stockNewslist(json_str, m_row) #stockNewsList 没有top 只有top下的5条 225 | self.CompanyNews(json_str) #stockNewsList 没有top 只有top下的5条 226 | self.marketAnalysis(json_str) 227 | self.IPOObservation(json_str) #stockNewsList 没有top 只有top下的5条 228 | 229 | def main(self, filename): 230 | self.xlsxname = filename 231 | #Fh.Style() 232 | Fh.request() 233 | Fh.getTopNew() 234 | Fh.getStockNews() 235 | 236 | Fh = FengHuang() 237 | -------------------------------------------------------------------------------- /src/Jrj_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | from openpyxl.styles import Font 5 | import json 6 | import time 7 | import datetime 8 | 9 | headers = { 10 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 11 | } 12 | 13 | class JinRongJie(object): 14 | def __init__(self): 15 | pass 16 | 17 | def Style(self): 18 | self.m_font = Font( 19 | size=12, 20 | bold=True, 21 | ) 22 | 23 | self.head_font = Font( 24 | size=14, 25 | bold=True, 26 | ) 27 | 28 | def get_TopNews(self): 29 | url = 'http://finance.jrj.com.cn/' 30 | for ll in range(3): 31 | try: 32 | self.data = requests.get(url, headers=headers, timeout=120) 33 | if self.data.status_code == 200: 34 | break 35 | except Exception as e: 36 | pass 37 | 38 | soup = BeautifulSoup(self.data.text, "lxml") 39 | 40 | wb = load_workbook(self.xlsxname) 41 | sheet = wb.create_sheet('Jrj') 42 | t_row = 1 43 | t_col = 1 44 | 45 | sheet.cell(row=t_row, column=t_col + 0, value="金融界财经") 46 | t_row = t_row + 1 47 | sheet.cell(row=t_row, column=t_col + 0, value="新闻标题") 48 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 49 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 50 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 51 | t_row = t_row + 1 52 | 53 | datalist = soup.find_all(class_="l1_top") 54 | for News in datalist: 55 | New = News.select('dl dt p') 56 | for m_new in New: 57 | data = m_new.find('a') 58 | m_url = data['href'] 59 | m_title = data.get_text() 60 | sheet.cell(row=t_row, column=t_col, value=m_title) 61 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 62 | t_row = t_row + 1 63 | try: 64 | wb.save(self.xlsxname) 65 | except Exception: 66 | print("JRJ Save Error = 1") 67 | 68 | def get_FinanceNews(self): #差不多4-5个小时内的热点新闻 69 | fin_time1 = time.strftime("%Y%m", time.localtime()) # year-month-day-hour-minute 70 | fin_time2 = time.strftime("%Y%m%d", time.localtime()) # year-month-day-hour-minute 71 | fin_url = 'http://finance.jrj.com.cn/xwk/{}/{}_1.shtml'.format(fin_time1, fin_time2) 72 | 73 | wb = load_workbook(self.xlsxname) 74 | sheet = wb.get_sheet_by_name('Jrj') 75 | t_row = sheet.max_row + 1 76 | t_col = 1 77 | 78 | sheet.cell(row=t_row + 1, column=t_col, value="财经频道新闻") 79 | sheet.cell(row=t_row + 2, column=t_col, value="新闻标题") 80 | sheet.cell(row=t_row + 2, column=t_col + 1, value="新闻链接") 81 | sheet.cell(row=t_row + 2, column=t_col + 2, value="新闻简介") 82 | sheet.cell(row=t_row + 2, column=t_col + 3, value="新闻时间") 83 | t_row = t_row + 3 84 | time_row = t_row 85 | 86 | data = None 87 | for ll in range(3): 88 | try: 89 | data = requests.get(fin_url, headers=headers, timeout=120) 90 | if data.status_code == 200: 91 | break 92 | except Exception as e: 93 | pass 94 | 95 | soup = BeautifulSoup(data.text, "lxml") 96 | datalist = soup.find_all(class_="list") 97 | flag = False 98 | for Newslist in datalist: 99 | #News = Newslist.select('li') 100 | News = Newslist.find_all('a') 101 | m_NewsTime = Newslist.find_all('span') 102 | for m_new in News: 103 | if flag == True: 104 | flag = False 105 | m_url = m_new['href'] 106 | m_title = m_new.get_text() 107 | sheet.cell(row=t_row, column=t_col, value=m_title) 108 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 109 | t_row = t_row + 1 110 | else: 111 | flag = True 112 | for new_time in m_NewsTime: 113 | m_time = new_time.get_text() 114 | sheet.cell(row=time_row, column=t_col + 3, value=m_time) 115 | time_row = time_row + 1 116 | try: 117 | wb.save(self.xlsxname) 118 | except Exception: 119 | print("JRJ Save Error = 2") 120 | 121 | def get_todayHot(self): 122 | url = 'http://biz.jrj.com.cn/biz_index.shtml' 123 | for ll in range(3): 124 | try: 125 | data = requests.get(url, headers=headers, timeout=120) 126 | if data.status_code == 200: 127 | break 128 | except Exception as e: 129 | pass 130 | 131 | soup = BeautifulSoup(data.text, "lxml") 132 | datalist = soup.find_all(class_="jrj-top10") 133 | 134 | wb = load_workbook(self.xlsxname) 135 | sheet = wb.get_sheet_by_name('Jrj') 136 | t_row = sheet.max_row + 2 137 | t_col = 1 138 | 139 | sheet.cell(row=t_row, column=t_col, value="24小时间热闻点击排行榜") 140 | t_row = t_row + 1 141 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 142 | sheet.cell(row=t_row, column=t_col + 0, value="新闻标题") 143 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 144 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 145 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 146 | t_row = t_row + 1 147 | 148 | flag = True 149 | for Newslist in datalist: 150 | if flag == True: 151 | News = Newslist.find_all('a') 152 | for m_new in News: 153 | m_title = m_new['title'] 154 | m_url = m_new['href'] 155 | sheet.cell(row=t_row, column=t_col, value=m_title) 156 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 157 | t_row = t_row + 1 158 | flag = False 159 | try: 160 | wb.save(self.xlsxname) 161 | except Exception: 162 | print("JRJ Save Error = 5") 163 | 164 | 165 | def get_Business(self): 166 | bu_time1 = time.strftime("%Y%m", time.localtime()) # year-month-day-hour-minute 167 | bu_time2 = time.strftime("%Y%m%d", time.localtime()) # year-month-day-hour-minute 168 | bus_url = 'http://biz.jrj.com.cn/xwk/{}/{}_1.shtml'.format(bu_time1, bu_time2) 169 | 170 | wb = load_workbook(self.xlsxname) 171 | sheet = wb.get_sheet_by_name('Jrj') 172 | t_row = sheet.max_row + 1 173 | t_col = 1 174 | 175 | sheet.cell(row=t_row + 1, column=t_col, value="商业频道新闻") 176 | sheet.cell(row=t_row + 2, column=t_col, value="新闻标题") 177 | sheet.cell(row=t_row + 2, column=t_col + 1, value="新闻链接") 178 | sheet.cell(row=t_row + 2, column=t_col + 2, value="新闻简介") 179 | sheet.cell(row=t_row + 2, column=t_col + 3, value="新闻时间") 180 | t_row = t_row + 3 181 | time_row = t_row 182 | 183 | data = None 184 | for ll in range(3): 185 | try: 186 | data = requests.get(bus_url, headers=headers, timeout=120) 187 | if data.status_code == 200: 188 | break 189 | except Exception as e: 190 | pass 191 | 192 | soup = BeautifulSoup(data.text, "lxml") 193 | datalist = soup.find_all(class_="list") 194 | flag = False 195 | for Newslist in datalist: 196 | # News = Newslist.select('li') 197 | News = Newslist.find_all('a') 198 | m_NewsTime = Newslist.find_all('span') 199 | for m_new in News: 200 | if flag == True: 201 | flag = False 202 | m_url = m_new['href'] 203 | m_title = m_new.get_text() 204 | sheet.cell(row=t_row, column=t_col, value=m_title) 205 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 206 | t_row = t_row + 1 207 | else: 208 | flag = True 209 | for new_time in m_NewsTime: 210 | m_time = new_time.get_text() 211 | sheet.cell(row=time_row, column=t_col + 3, value=m_time) 212 | time_row = time_row + 1 213 | try: 214 | wb.save(self.xlsxname) 215 | except Exception: 216 | print("JRJ Save Error = 3") 217 | 218 | """ 219 | def get_Science(self): 220 | url = 'http://finance.jrj.com.cn/tech/tech_index.shtml' 221 | sci_time = time.strftime("%Y-%m-%d", time.localtime()) # year-month-day-hour-minute 222 | """ 223 | 224 | def get_yesScience(self): 225 | sci_time1 = time.strftime("%Y%m", time.localtime()) # year-month-day-hour-minute 226 | sci_time2 = time.strftime("%Y%m%d", time.localtime()) # year-month-day-hour-minute 227 | """ 228 | yesterday = time.strftime("%d", time.localtime()) # year-month-day-hour-minute 229 | yesterday = 1 230 | if yesterday == 1: 231 | # 获取当前日期 232 | now_time = datetime.datetime.now() 233 | # 获取本月的第一天 234 | end_day_in_mouth = now_time.replace(day=1) 235 | # 获取上月的最后一天 236 | next_mouth = end_day_in_mouth - datetime.timedelta(days=1) 237 | print(next_mouth.month) 238 | """ 239 | sci_url = 'http://biz.jrj.com.cn/xwk/{}/{}_1.shtml'.format(sci_time1, sci_time2) 240 | 241 | wb = load_workbook(self.xlsxname) 242 | sheet = wb.get_sheet_by_name('Jrj') 243 | t_row = sheet.max_row + 1 244 | t_col = 1 245 | 246 | sheet.cell(row=t_row + 1, column=t_col, value="科技频道新闻") 247 | sheet.cell(row=t_row + 2, column=t_col, value="新闻标题") 248 | sheet.cell(row=t_row + 2, column=t_col + 1, value="新闻链接") 249 | sheet.cell(row=t_row + 2, column=t_col + 2, value="新闻简介") 250 | sheet.cell(row=t_row + 2, column=t_col + 3, value="新闻时间") 251 | t_row = t_row + 3 252 | time_row = t_row 253 | data = '' 254 | for ll in range(3): 255 | try: 256 | data = requests.get(sci_url, headers=headers, timeout=120) 257 | if data.status_code == 200: 258 | break 259 | except Exception as e: 260 | pass 261 | soup = BeautifulSoup(data.text, "lxml") 262 | datalist = soup.find_all(class_="list") 263 | flag = False 264 | for Newslist in datalist: 265 | # News = Newslist.select('li') 266 | News = Newslist.find_all('a') 267 | m_NewsTime = Newslist.find_all('span') 268 | for m_new in News: 269 | if flag == True: 270 | flag = False 271 | m_url = m_new['href'] 272 | m_title = m_new.get_text() 273 | sheet.cell(row=t_row, column=t_col, value=m_title) 274 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 275 | t_row = t_row + 1 276 | else: 277 | flag = True 278 | for new_time in m_NewsTime: 279 | m_time = new_time.get_text() 280 | sheet.cell(row=time_row, column=t_col + 3, value=m_time) 281 | time_row = time_row + 1 282 | try: 283 | wb.save(self.xlsxname) 284 | except Exception: 285 | print("JRJ Save Error = 4") 286 | 287 | def main(self, filename): 288 | self.xlsxname = filename 289 | Jrj.get_TopNews() 290 | Jrj.get_todayHot() 291 | Jrj.get_FinanceNews() 292 | Jrj.get_Business() 293 | # Jrj.get_Science() 294 | Jrj.get_yesScience() 295 | 296 | Jrj = JinRongJie() 297 | -------------------------------------------------------------------------------- /src/Platform.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import os 3 | import shutil 4 | import time 5 | 6 | class Files(object): 7 | def __init__(self): 8 | pass 9 | 10 | def get_platform(self): 11 | sys = platform.system() 12 | if sys == "Windows": 13 | return True 14 | elif sys == "Linux": 15 | return False 16 | 17 | def file_move(self, platform): 18 | if platform: 19 | self.win_News() 20 | else: 21 | self.lin_News() 22 | 23 | def lin_News(self): 24 | path = "./Finance/News/" 25 | filename = "./News_Finance.xlsx" 26 | isExists = os.path.exists(path) 27 | if not isExists: 28 | os.mkdir(path) 29 | #filetime = time.strftime("%Y_%m_%d_%H_%M", time.localtime()) # year-month-day-hour-minute 30 | filetime = time.strftime("%Y_%m_%d_%H", time.localtime()) # year-month-day-hour-minute 31 | path2 = path + "闻讯__" + filetime + "时.xlsx" 32 | shutil.move(filename, path2) 33 | 34 | 35 | def win_News(self): 36 | desktop_path = os.path.join(os.path.expanduser('~'),"Desktop") #获取桌面路径 37 | filename = desktop_path + "\\Finance\\News_Finance.xlsx" 38 | path = desktop_path +"\\Finance\\News\\" 39 | 40 | isExists = os.path.exists(path) 41 | if not isExists: 42 | os.mkdir(path) 43 | #filetime = time.strftime("%Y_%m_%d_%H_%M", time.localtime()) #year-month-day-hour-minute 44 | filetime = time.strftime("%Y_%m_%d_%H", time.localtime()) #year-month-day-hour-minute 45 | path2 = path + "闻讯__" + filetime + "时.xlsx" 46 | shutil.move(filename, path2) 47 | 48 | def linux_filename(self): 49 | path = "./Finance/" 50 | isExists = os.path.exists(path) 51 | if not isExists: 52 | os.mkdir(path) 53 | # self.lin_History() 54 | linux_file = "./News_Finance.xlsx" 55 | return linux_file 56 | 57 | def win_filename(self): 58 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 59 | path = desktop_path + "\\Finance\\" 60 | isExists = os.path.exists(path) 61 | if not isExists: 62 | os.mkdir(path) 63 | 64 | win_file = desktop_path + "\\Finance\\News_Finance.xlsx" 65 | return win_file 66 | 67 | def pause(self): 68 | os.system('pause') 69 | 70 | """ 71 | def win_mkdir(self): 72 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 73 | dir = os.path.exists(desktop_path + "\\Finance") 74 | if not dir: 75 | os.mkdir(dir) 76 | """ 77 | def getwinfile(self): 78 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 79 | filename = desktop_path + "\\Finance\\News_Finance.xlsx" 80 | path = desktop_path + "\\Finance\\News\\" 81 | # filetime = time.strftime("%Y_%m_%d_%H_%M", time.localtime()) #year-month-day-hour-minute 82 | filetime = time.strftime("%Y_%m_%d", time.localtime()) # year-month-day-hour-minute 83 | path2 = path + "闻讯__" + filetime + ".xlsx" 84 | return path2 85 | 86 | def getlinfile(self): 87 | path = "./Finance/News/" 88 | filename = "./News_Finance.xlsx" 89 | isExists = os.path.exists(path) 90 | # filetime = time.strftime("%Y_%m_%d_%H_%M", time.localtime()) # year-month-day-hour-minute 91 | filetime = time.strftime("%Y_%m_%d", time.localtime()) # year-month-day-hour-minute 92 | path2 = path + "闻讯__" + filetime + ".xlsx" 93 | return path2 94 | 95 | 96 | def getfilename(self): 97 | if self.get_platform() == True: 98 | return self.getwinfile() 99 | else: 100 | return self.getlinfile() 101 | 102 | def filename(self): 103 | filetime = time.strftime("%Y_%m_%d", time.localtime()) # year-month-day-hour-minute 104 | path2 = "闻讯__" + filetime + ".xlsx" 105 | return path2 106 | 107 | def getwinpath(self): 108 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 109 | path = desktop_path + "\\Finance\\" + " \\" 110 | return path 111 | 112 | def getlinpath(self): 113 | path = "./Finance/" + " /" 114 | return path 115 | 116 | def getpath(self): 117 | if self.get_platform() == True: 118 | return self.getwinpath() 119 | else: 120 | return self.getlinpath() 121 | 122 | 123 | pt = Files() -------------------------------------------------------------------------------- /src/Self_Stock.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook, Workbook 4 | import json 5 | import threading 6 | import time 7 | import re 8 | import os 9 | import wget 10 | from src.Platform import pt 11 | #处理个股版本,包含交易明细、买卖盘、券商机构等。 12 | #上层目录Code.txt 添加代码 13 | #失效不再更新,自行抓包获取。 14 | 15 | 16 | headers = { 17 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 18 | } 19 | 20 | class SelfStock(object): 21 | threadLock = threading.Lock() 22 | def __init__(self): 23 | self.stop = True 24 | #self.xlsxname = file_name 25 | 26 | def Deal_Xq_quote(self, data, name): 27 | self.threadLock.acquire() 28 | file_name = self.get_filename(name) 29 | try: 30 | wb = load_workbook(file_name) 31 | try: 32 | sheet = wb.get_sheet_by_name(name) 33 | ws = wb[name] 34 | wb.remove(ws) 35 | sheet = wb.create_sheet(name, 0) 36 | except: 37 | sheet = wb.create_sheet(name) 38 | except: 39 | wb = Workbook() 40 | ws = wb['Sheet'] 41 | wb.remove(ws) 42 | sheet = wb.create_sheet(name) 43 | 44 | t_row = 1 45 | t_col = 1 46 | 47 | data_json = data['data'] 48 | data_items = data_json['items'] 49 | data_mk = data_items[0]['market'] 50 | data_quote = data_items[0]['quote'] 51 | #print(data_quote) 52 | 53 | sheet.cell(row=t_row, column=t_col, value="股票代码") 54 | sheet.cell(row=t_row, column=t_col + 1, value="股票名称") 55 | sheet.cell(row=t_row, column=t_col + 2, value="交易状态") 56 | sheet.cell(row=t_row, column=t_col + 3, value="更新时间") 57 | t_row = t_row + 1 58 | m_status = data_mk['status'] 59 | stock_code = data_quote['symbol'] 60 | stock_name = data_quote['name'] 61 | m_time = data_quote['timestamp'] 62 | timeStamp = float(m_time / 1000) #13位时间戳 63 | timeArray = time.localtime(timeStamp) 64 | otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) 65 | 66 | sheet.cell(row=t_row, column=t_col, value=stock_code) 67 | sheet.cell(row=t_row, column=t_col + 1, value=stock_name) 68 | sheet.cell(row=t_row, column=t_col + 2, value=m_status) 69 | sheet.cell(row=t_row, column=t_col + 3, value=otherStyleTime) 70 | t_row = t_row + 2 71 | 72 | sheet.cell(row=t_row, column=t_col + 0, value="当前价格") 73 | sheet.cell(row=t_row, column=t_col + 1, value="涨跌价格") 74 | sheet.cell(row=t_row, column=t_col + 2, value="涨跌幅度") 75 | sheet.cell(row=t_row, column=t_col + 3, value="开盘价格") 76 | sheet.cell(row=t_row, column=t_col + 4, value="当前新高") 77 | sheet.cell(row=t_row, column=t_col + 5, value="当前新低") 78 | sheet.cell(row=t_row, column=t_col + 6, value="昨日收盘") 79 | sheet.cell(row=t_row, column=t_col + 7, value="平均价格") 80 | sheet.cell(row=t_row, column=t_col + 8, value="涨停价格") 81 | sheet.cell(row=t_row, column=t_col + 9, value="跌停价格") 82 | sheet.cell(row=t_row, column=t_col + 10, value="52周最高") 83 | sheet.cell(row=t_row, column=t_col + 11, value="52周最低") 84 | t_row = t_row + 1 85 | 86 | m_current = data_quote['current'] 87 | m_percent = data_quote['percent'] #涨跌幅度 88 | m_chg = data_quote['chg'] #涨跌价格 89 | m_open = data_quote['open'] #开盘价 90 | m_yesclose = data_quote['last_close'] #昨收 91 | m_high = data_quote['high'] 92 | m_low = data_quote['low'] 93 | m_avg_price = data_quote['avg_price'] 94 | m_limit_up = data_quote['limit_up'] #涨停 95 | m_limit_down = data_quote['limit_down'] #跌停 96 | m_high52w = data_quote['high52w'] #52周最高 97 | m_low52w = data_quote['low52w'] #52周最低 98 | sheet.cell(row=t_row, column=t_col + 0, value=m_current) 99 | sheet.cell(row=t_row, column=t_col + 1, value=m_chg) 100 | sheet.cell(row=t_row, column=t_col + 2, value=str(m_percent) + "%") 101 | sheet.cell(row=t_row, column=t_col + 3, value=m_open) 102 | sheet.cell(row=t_row, column=t_col + 4, value=m_high) 103 | sheet.cell(row=t_row, column=t_col + 5, value=m_low) 104 | sheet.cell(row=t_row, column=t_col + 6, value=m_yesclose) 105 | sheet.cell(row=t_row, column=t_col + 7, value=m_avg_price) 106 | sheet.cell(row=t_row, column=t_col + 8, value=m_limit_up) 107 | sheet.cell(row=t_row, column=t_col + 9, value=m_limit_down) 108 | sheet.cell(row=t_row, column=t_col + 10, value=m_high52w) 109 | sheet.cell(row=t_row, column=t_col + 11, value=m_low52w) 110 | t_row = t_row + 2 111 | 112 | 113 | sheet.cell(row=t_row, column=t_col + 0, value="成交额(/万)") 114 | sheet.cell(row=t_row, column=t_col + 1, value="成交量(/万手)") 115 | sheet.cell(row=t_row, column=t_col + 2, value="换手率") 116 | sheet.cell(row=t_row, column=t_col + 3, value="量比") 117 | sheet.cell(row=t_row, column=t_col + 4, value="振幅") 118 | sheet.cell(row=t_row, column=t_col + 5, value="市盈率TTM") 119 | sheet.cell(row=t_row, column=t_col + 6, value="市盈率(动)") 120 | sheet.cell(row=t_row, column=t_col + 7, value="市盈率(静)") 121 | sheet.cell(row=t_row, column=t_col + 8, value="市净率") 122 | sheet.cell(row=t_row, column=t_col + 9, value="总股本(/万)") 123 | sheet.cell(row=t_row, column=t_col + 10, value="流通股(/万)") 124 | sheet.cell(row=t_row, column=t_col + 11, value="总市值(/亿)") 125 | sheet.cell(row=t_row, column=t_col + 12, value="流通市值(/亿)") 126 | t_row = t_row + 1 127 | 128 | m_amount = data_quote['amount'] #成交额 129 | if m_amount == None: #防止停牌、退市等情况股价不再更新 130 | self.stop = False 131 | self.threadLock.release() 132 | return 133 | m_turnover_rate = data_quote['turnover_rate'] #换手:0.74% 134 | m_volume = data_quote['volume'] #成交量 135 | m_amplitude = data_quote['amplitude'] #振幅 136 | m_total_shares = data_quote['total_shares'] #总股本 137 | m_float_shares = data_quote['float_shares'] #流通股 138 | m_volume_ratio = data_quote['volume_ratio'] #量比 139 | m_pe_ttm = data_quote['pe_ttm'] #市盈率 140 | m_pe_forecast = data_quote['pe_forecast'] #动态市盈率 141 | m_pe_lyr = data_quote['pe_lyr'] #静态市盈率 142 | m_pb = data_quote['pb'] #市净率 143 | m_profit = data_quote['profit'] #年报利润 144 | m_profit_four = data_quote['profit_four'] #也是利润 不清楚 145 | m_profit_forecast = data_quote['profit_forecast'] 146 | m_market_capital = data_quote['market_capital'] #总市值 147 | m_float_market_capital = data_quote['float_market_capital'] #流通市值 148 | sheet.cell(row=t_row, column=t_col + 0, value=round(m_amount / 10000, 2)) 149 | sheet.cell(row=t_row, column=t_col + 1, value=round(m_volume / 10000, 2)) 150 | sheet.cell(row=t_row, column=t_col + 2, value=str(m_turnover_rate) + "%") 151 | sheet.cell(row=t_row, column=t_col + 3, value=m_volume_ratio) 152 | sheet.cell(row=t_row, column=t_col + 4, value=str(m_amplitude) + "%") 153 | sheet.cell(row=t_row, column=t_col + 5, value=m_pe_ttm) 154 | sheet.cell(row=t_row, column=t_col + 6, value=m_pe_forecast) 155 | sheet.cell(row=t_row, column=t_col + 7, value=m_pe_lyr) 156 | sheet.cell(row=t_row, column=t_col + 8, value=m_pb) 157 | sheet.cell(row=t_row, column=t_col + 9, value=round(m_total_shares / 10000, 2)) 158 | sheet.cell(row=t_row, column=t_col + 10, value=round(m_float_shares / 10000, 2)) 159 | sheet.cell(row=t_row, column=t_col + 11, value=round(m_market_capital / 100000000, 2)) 160 | sheet.cell(row=t_row, column=t_col + 12, value=round(m_float_market_capital / 100000000, 2)) 161 | 162 | self.threadLock.release() 163 | 164 | try: 165 | wb.save(file_name) 166 | except Exception: 167 | print("Self_Stock Save Error = Xq_quote") 168 | 169 | def Deal_Xq_distribution(self, data, name): 170 | self.threadLock.acquire() 171 | file_name = self.get_filename(name) 172 | wb = load_workbook(file_name) 173 | sheet = wb.get_sheet_by_name(name) 174 | 175 | t_row = sheet.max_row + 3 176 | t_col = 1 177 | 178 | m_text = data['data']['analysis'][0] #今日主力净流入XX亿 179 | sheet.cell(row=t_row, column=t_col, value=m_text) 180 | t_row = t_row + 1 181 | 182 | sheet.cell(row=t_row, column=t_col, value="资金成交分布(/万)") 183 | sheet.cell(row=t_row, column=6, value="净流入(/万)") 184 | t_row = t_row + 1 185 | 186 | m_data = data['data']['distribution'] 187 | m_sell = m_data['sell'] # 188 | m_buy = m_data['buy'] 189 | 190 | sheet.cell(row=t_row, column=t_col, value="特大单卖出") 191 | sheet.cell(row=t_row + 1, column=t_col, value="大单卖出") 192 | sheet.cell(row=t_row + 2, column=t_col, value="中单卖出") 193 | sheet.cell(row=t_row + 3, column=t_col, value="小单卖出") 194 | sheet.cell(row=t_row + 4, column=t_col, value="合计") 195 | se_xlarge = m_sell['xlarge'] 196 | se_large = m_sell['large'] 197 | se_medium = m_sell['medium'] 198 | se_small = m_sell['small'] 199 | sum_sell = se_large + se_large + se_medium + se_small 200 | 201 | by_xlarge = m_buy['xlarge'] 202 | by_large = m_buy['large'] 203 | by_medium = m_buy['medium'] 204 | by_small = m_buy['small'] 205 | sum_buy = by_xlarge + by_large + by_medium + by_small 206 | t_col = t_col + 1 207 | sheet.cell(row=t_row, column=t_col, value=round(se_xlarge / 10000, 2)) 208 | sheet.cell(row=t_row + 1, column=t_col, value=round(se_large / 10000, 2)) 209 | sheet.cell(row=t_row + 2, column=t_col, value=round(se_medium / 10000, 2)) 210 | sheet.cell(row=t_row + 3, column=t_col, value=round(se_small / 10000, 2)) 211 | sheet.cell(row=t_row + 4, column=t_col, value=round(sum_sell / 10000, 2)) 212 | t_col = t_col + 2 213 | 214 | sheet.cell(row=t_row, column=t_col, value=round(by_xlarge / 10000, 2)) 215 | sheet.cell(row=t_row + 1, column=t_col, value=round(by_large / 10000, 2)) 216 | sheet.cell(row=t_row + 2, column=t_col, value=round(by_medium / 10000, 2)) 217 | sheet.cell(row=t_row + 3, column=t_col, value=round(by_small / 10000, 2)) 218 | sheet.cell(row=t_row + 4, column=t_col, value=round(sum_buy / 10000, 2)) 219 | t_col = t_col + 1 220 | 221 | sheet.cell(row=t_row, column=t_col, value="特大单买入") 222 | sheet.cell(row=t_row + 1, column=t_col, value="大单买入") 223 | sheet.cell(row=t_row + 2, column=t_col, value="中单买入") 224 | sheet.cell(row=t_row + 3, column=t_col, value="小单买入 ") 225 | sheet.cell(row=t_row + 4, column=t_col, value="净流入 ") 226 | 227 | m_xlarge = round((by_xlarge / 10000) - (se_xlarge / 10000), 2) 228 | m_large = round((by_large / 10000) - (se_large / 10000), 2) 229 | m_medium = round((by_medium / 10000) - (se_medium / 10000), 2) 230 | m_small = round((by_small / 10000) - (se_small / 10000), 2) 231 | sheet.cell(row=t_row, column=6, value=m_xlarge) 232 | sheet.cell(row=t_row + 1, column=6, value=m_large) 233 | sheet.cell(row=t_row + 2, column=6, value=m_medium) 234 | sheet.cell(row=t_row + 3, column=6, value=m_small) 235 | sheet.cell(row=t_row + 4, column=6, value=round(sum_buy - sum_sell, 2) / 10000) 236 | 237 | self.threadLock.release() 238 | 239 | try: 240 | wb.save(file_name) 241 | except Exception: 242 | print("Self_Stock Save Error = distribution") 243 | 244 | 245 | def Deal_Xq_query(self, data, name): #主力历史是个持续更新的东西 保存到一个新的文件中 分为第一次使用或者长期更新 246 | self.threadLock.acquire() 247 | file_name = self.get_filename(name) 248 | wb = load_workbook(file_name) 249 | new_sheet = False 250 | try: 251 | sheet = wb.get_sheet_by_name("资金流向历史") 252 | except: 253 | sheet = wb.create_sheet("资金流向历史") 254 | new_sheet = True 255 | sheet.cell(row=1, column=1, value="日期") 256 | sheet.cell(row=1, column=2, value="收盘价") 257 | sheet.cell(row=1, column=3, value="涨跌幅") 258 | sheet.cell(row=1, column=4, value="主力资金净流入") 259 | sheet.cell(row=1, column=5, value="特大单净流入") 260 | sheet.cell(row=1, column=6, value="大单净流入") 261 | sheet.cell(row=1, column=7, value="中单净流入") 262 | sheet.cell(row=1, column=8, value="小单净流入") 263 | 264 | m_data = data['data']['items'] 265 | new_max_line = 20 + 1 # 标题一行 内容20行 266 | t_row = sheet.max_row + 1 267 | n = 0 268 | t_col = 1 269 | for m_json in m_data: 270 | m_small = m_json['small'] 271 | m_large = m_json['large'] 272 | m_xlarge = m_json['xlarge'] 273 | m_medium = m_json['medium'] 274 | m_close = m_json['close'] # 收盘价 275 | m_percent = m_json['percent'] # 涨跌幅 276 | m_amount = m_json['amount'] # 主力 277 | m_time = m_json['timestamp'] 278 | timeStamp = float(m_time / 1000) # 13位时间戳 279 | timeArray = time.localtime(timeStamp) 280 | otherStyleTime = time.strftime("%Y-%m-%d", timeArray) # 年月日 281 | 282 | if new_sheet == False: 283 | cell = sheet.cell(t_row - 1, 1).value 284 | if cell == otherStyleTime: 285 | t_row = t_row - 1 286 | sheet.cell(row=t_row, column=t_col, value=otherStyleTime) 287 | sheet.cell(row=t_row, column=t_col + 1, value=m_close) 288 | sheet.cell(row=t_row, column=t_col + 2, value=str(m_percent) + "%") 289 | sheet.cell(row=t_row, column=t_col + 3, value=round(m_amount / 10000, 2)) 290 | sheet.cell(row=t_row, column=t_col + 4, value=round(m_xlarge / 10000, 2)) 291 | sheet.cell(row=t_row, column=t_col + 5, value=round(m_large / 10000, 2)) 292 | sheet.cell(row=t_row, column=t_col + 6, value=round(m_medium / 10000, 2)) 293 | sheet.cell(row=t_row, column=t_col + 7, value=round(m_small / 10000, 2)) 294 | break 295 | elif n < 2: 296 | sheet.cell(row=t_row, column=t_col, value=otherStyleTime) 297 | sheet.cell(row=t_row, column=t_col + 1, value=m_close) 298 | sheet.cell(row=t_row, column=t_col + 2, value=str(m_percent) + "%") 299 | sheet.cell(row=t_row, column=t_col + 3, value=round(m_amount / 10000, 2)) 300 | sheet.cell(row=t_row, column=t_col + 4, value=round(m_xlarge / 10000, 2)) 301 | sheet.cell(row=t_row, column=t_col + 5, value=round(m_large / 10000, 2)) 302 | sheet.cell(row=t_row, column=t_col + 6, value=round(m_medium / 10000, 2)) 303 | sheet.cell(row=t_row, column=t_col + 7, value=round(m_small / 10000, 2)) 304 | t_row = t_row - 1 305 | n = n + 1 306 | else: 307 | break 308 | elif new_sheet == True: # 新文件/新表 写入全部日期 309 | if new_max_line > 1: 310 | sheet.cell(row=new_max_line, column=t_col, value=otherStyleTime) 311 | sheet.cell(row=new_max_line, column=t_col + 1, value=m_close) 312 | sheet.cell(row=new_max_line, column=t_col + 2, value=str(m_percent) + "%") 313 | sheet.cell(row=new_max_line, column=t_col + 3, value=round(m_amount / 10000, 2)) 314 | sheet.cell(row=new_max_line, column=t_col + 4, value=round(m_xlarge / 10000, 2)) 315 | sheet.cell(row=new_max_line, column=t_col + 5, value=round(m_large / 10000, 2)) 316 | sheet.cell(row=new_max_line, column=t_col + 6, value=round(m_medium / 10000, 2)) 317 | sheet.cell(row=new_max_line, column=t_col + 7, value=round(m_small / 10000, 2)) 318 | new_max_line = new_max_line - 1 319 | 320 | self.threadLock.release() 321 | 322 | try: 323 | wb.save(file_name) 324 | except: 325 | print("Self_Stock Save Error = query") 326 | 327 | """ 328 | flag = True #已经存在为true 329 | new_sheet = True #新sheet 330 | 331 | if if_os == True: 332 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 333 | path = desktop_path + "\\Finance\\History\\闻讯_主力资金历史.xlsx" 334 | isExists = os.path.exists(path) 335 | if not isExists: 336 | flag = False 337 | new_sheet = True 338 | if self.first == 0: 339 | self.wb = Workbook() 340 | ws = self.wb['Sheet'] 341 | self.wb.remove(ws) 342 | self.sheet = self.wb.create_sheet(name) 343 | self.first += 1 344 | else: 345 | self.wb = load_workbook(desktop_path + "\\Finance\\Main_History.xlsx") 346 | try: 347 | self.sheet = self.wb.get_sheet_by_name(name) 348 | new_sheet = False 349 | except: 350 | self.sheet = self.wb.create_sheet(name) 351 | new_sheet = True 352 | else: 353 | self.wb = load_workbook(path) 354 | try: 355 | self.sheet = self.wb.get_sheet_by_name(name) 356 | new_sheet = False 357 | except: 358 | self.sheet = self.wb.create_sheet(name) 359 | new_sheet = True 360 | elif if_os == False: 361 | d_path = "./Finance/History/" 362 | paths = d_path + "闻讯_主力资金历史.xlsx" 363 | isExists = os.path.exists(paths) 364 | if not isExists: 365 | flag = False #不存在 366 | new_sheet = True 367 | if self.first == 0: 368 | self.wb = Workbook() 369 | ws = self.wb['Sheet'] 370 | self.wb.remove(ws) 371 | self.sheet = self.wb.create_sheet(name) 372 | self.first += 1 373 | else: 374 | self.wb = load_workbook("./Main_History.xlsx") 375 | try: 376 | self.sheet = self.wb.get_sheet_by_name(name) 377 | new_sheet = False 378 | except: 379 | self.sheet = self.wb.create_sheet(name) 380 | new_sheet = True 381 | else: 382 | self.wb = load_workbook(paths) 383 | try: 384 | self.sheet = self.wb.get_sheet_by_name(name) 385 | new_sheet = False 386 | except: 387 | self.sheet = self.wb.create_sheet(name) 388 | new_sheet = True 389 | 390 | if new_sheet == True: 391 | self.sheet.cell(row=1, column=1, value="日期") 392 | self.sheet.cell(row=1, column=2, value="收盘价") 393 | self.sheet.cell(row=1, column=3, value="涨跌幅") 394 | self.sheet.cell(row=1, column=4, value="主力资金净流入") 395 | self.sheet.cell(row=1, column=5, value="特大单净流入") 396 | self.sheet.cell(row=1, column=6, value="大单净流入") 397 | self.sheet.cell(row=1, column=7, value="中单净流入") 398 | self.sheet.cell(row=1, column=8, value="小单净流入") 399 | 400 | max_row = 20 + 1 #标题一行 内容20行 401 | n = 0 402 | t_row = self.sheet.max_row + 1 403 | t_col = 1 404 | for m_json in m_data: 405 | m_small = m_json['small'] 406 | m_large = m_json['large'] 407 | m_xlarge = m_json['xlarge'] 408 | m_medium = m_json['medium'] 409 | m_close = m_json['close'] # 收盘价 410 | m_percent = m_json['percent'] # 涨跌幅 411 | m_amount = m_json['amount'] #主力 412 | m_time = m_json['timestamp'] 413 | timeStamp = float(m_time / 1000) # 13位时间戳 414 | timeArray = time.localtime(timeStamp) 415 | otherStyleTime = time.strftime("%Y-%m-%d", timeArray) # 年月日 416 | 417 | if flag == True: 418 | if new_sheet == False: 419 | cell = self.sheet.cell(t_row - 1, 1).value 420 | if cell == otherStyleTime: 421 | break 422 | elif n < 2: 423 | self.sheet.cell(row=t_row, column= t_col, value=otherStyleTime) 424 | self.sheet.cell(row=t_row, column= t_col + 1, value=m_close) 425 | self.sheet.cell(row=t_row, column= t_col + 2, value=str(m_percent) + "%") 426 | self.sheet.cell(row=t_row, column= t_col + 3, value=round(m_amount / 10000, 2)) 427 | self.sheet.cell(row=t_row, column= t_col + 4, value=round(m_xlarge / 10000, 2)) 428 | self.sheet.cell(row=t_row, column= t_col + 5, value=round(m_large / 10000, 2)) 429 | self.sheet.cell(row=t_row, column= t_col + 6, value=round(m_medium / 10000, 2)) 430 | self.sheet.cell(row=t_row, column= t_col + 7, value=round(m_small / 10000, 2)) 431 | t_row = t_row - 1 432 | n = n + 1 433 | else: 434 | break 435 | elif new_sheet == True: #新文件/新表 写入全部日期 436 | if max_row > 1: 437 | self.sheet.cell(row=max_row, column=t_col, value=otherStyleTime) 438 | self.sheet.cell(row=max_row, column=t_col + 1, value=m_close) 439 | self.sheet.cell(row=max_row, column=t_col + 2, value=str(m_percent) + "%") 440 | self.sheet.cell(row=max_row, column= t_col + 3, value=round(m_amount / 10000, 2)) 441 | self.sheet.cell(row=max_row, column= t_col + 4, value=round(m_xlarge / 10000, 2)) 442 | self.sheet.cell(row=max_row, column= t_col + 5, value=round(m_large / 10000, 2)) 443 | self.sheet.cell(row=max_row, column= t_col + 6, value=round(m_medium / 10000, 2)) 444 | self.sheet.cell(row=max_row, column= t_col + 7, value=round(m_small / 10000, 2)) 445 | max_row = max_row - 1 446 | elif flag == False: # 新文件/新表 写入全部日期 447 | if max_row > 1: 448 | self.sheet.cell(row=max_row, column=t_col, value=otherStyleTime) 449 | self.sheet.cell(row=max_row, column=t_col + 1, value=m_close) 450 | self.sheet.cell(row=max_row, column=t_col + 2, value=str(m_percent) + "%") 451 | self.sheet.cell(row=max_row, column=t_col + 3, value=round(m_amount / 10000, 2)) 452 | self.sheet.cell(row=max_row, column=t_col + 4, value=round(m_xlarge / 10000, 2)) 453 | self.sheet.cell(row=max_row, column=t_col + 5, value=round(m_large / 10000, 2)) 454 | self.sheet.cell(row=max_row, column=t_col + 6, value=round(m_medium / 10000, 2)) 455 | self.sheet.cell(row=max_row, column=t_col + 7, value=round(m_small / 10000, 2)) 456 | max_row = max_row - 1 457 | 458 | self.threadLock.release() 459 | if if_os == True: 460 | if flag == True: 461 | try: 462 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 463 | path = desktop_path + "\\Finance\\History\\闻讯_主力资金历史.xlsx" 464 | self.wb.save(path) 465 | except: 466 | print("Self_Stock Save Error = query_2_1") 467 | elif flag == False: 468 | try: 469 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") 470 | path = desktop_path + "\\Finance\\Main_History.xlsx" 471 | self.wb.save(path) 472 | except: 473 | print("Self_Stock Save Error = query_2_2") 474 | elif if_os == False: 475 | if flag == True: 476 | try: 477 | d_path = "./Finance/History/" 478 | path = d_path + "闻讯_主力资金历史.xlsx" 479 | self.wb.save(path) 480 | except: 481 | print("Self_Stock Save Error = query_2_1") 482 | elif flag == False: 483 | try: 484 | file_name = "./Main_History.xlsx" 485 | self.wb.save(file_name) 486 | except: 487 | print("Self_Stock Save Error = query_2_2") 488 | """ 489 | 490 | def Deal_Xq_blocktrans(self, data, name): 491 | self.threadLock.acquire() 492 | file_name = self.get_filename(name) 493 | wb = load_workbook(file_name) 494 | sheet = wb.get_sheet_by_name(name) 495 | 496 | t_row = sheet.max_row + 3 497 | t_col = 1 498 | sheet.cell(row=t_row, column=t_col, value="大宗交易") 499 | t_row = t_row + 1 500 | sheet.cell(row=t_row, column=t_col, value="成交价") 501 | sheet.cell(row=t_row, column=t_col + 1, value="成交量(/股)") 502 | sheet.cell(row=t_row, column=t_col + 2, value="成交额(/万)") 503 | sheet.cell(row=t_row, column=t_col + 3, value="溢价率") 504 | sheet.cell(row=t_row, column=t_col + 4, value="交易时间") 505 | sheet.cell(row=t_row, column=t_col + 5, value="买方营业部") 506 | sheet.cell(row=t_row, column=t_col + 6, value="卖方营业部") 507 | t_row = t_row + 1 508 | 509 | m_data = data['data'] 510 | data_items = m_data['items'] 511 | 512 | for m_json in data_items: 513 | m_vol = m_json['vol'] 514 | m_seller = m_json['sell_branch_org_name'] 515 | m_premium = m_json['premium_rat'] 516 | m_trans = m_json['trans_amt'] 517 | m_time = m_json['td_date'] 518 | m_buyer = m_json['buy_branch_org_name'] 519 | m_price = m_json['trans_price'] 520 | 521 | timeStamp = float(m_time / 1000) # 13位时间戳 522 | timeArray = time.localtime(timeStamp) 523 | m_date = time.strftime("%Y-%m-%d", timeArray) 524 | 525 | sheet.cell(row=t_row, column=t_col, value=m_price) 526 | sheet.cell(row=t_row, column=t_col + 1, value=m_vol) 527 | sheet.cell(row=t_row, column=t_col + 2, value=round(m_trans / 10000, 2)) 528 | sheet.cell(row=t_row, column=t_col + 3, value=str(m_premium) + "%") 529 | sheet.cell(row=t_row, column=t_col + 4, value=m_date) 530 | sheet.cell(row=t_row, column=t_col + 5, value=m_seller) 531 | sheet.cell(row=t_row, column=t_col + 6, value=m_buyer) 532 | t_row = t_row + 1 533 | 534 | self.threadLock.release() 535 | 536 | try: 537 | wb.save(file_name) 538 | except: 539 | print("Self_Stock Save Error = blocktrans") 540 | 541 | 542 | def mkdir_stock(self): 543 | platform = pt.get_platform() 544 | if platform == True: 545 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 546 | path = desktop_path + "\\Finance\\Stock\\" 547 | isExists = os.path.exists(path) 548 | if not isExists: 549 | os.mkdir(path) 550 | return path 551 | else: 552 | path = "./Finance/Stock/" 553 | isExists = os.path.exists(path) 554 | if not isExists: 555 | os.mkdir(path) 556 | return path 557 | 558 | 559 | def get_path(self, name): 560 | platform = pt.get_platform() 561 | if platform == True: 562 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 563 | path = desktop_path + "\\Finance\\Stock\\{}\\".format(name) 564 | isExists = os.path.exists(path) 565 | if not isExists: 566 | os.mkdir(path) 567 | return path 568 | else: 569 | path = "./Finance/Stock/{}/".format(name) 570 | isExists = os.path.exists(path) 571 | if not isExists: 572 | os.mkdir(path) 573 | return path 574 | 575 | 576 | def get_filename(self, name): 577 | platform = pt.get_platform() 578 | if platform == True: 579 | desktop_path = os.path.join(os.path.expanduser('~'), "Desktop") # 获取桌面路径 580 | win_file = desktop_path + "\\Finance\\Stock\\{}\\".format(name) + name + ".xlsx" 581 | return win_file 582 | else: 583 | lin_file = "./Finance/Stock/{}/".format(name) + name + ".xlsx" 584 | return lin_file 585 | 586 | 587 | def Download_Xlsx(self, m_url, path, name, m_time): #这个本来想写入伊利xlsx的 可是格式问题 openpyxl不能load 暂时这样吧 588 | #filetime = time.strftime("%Y-", time.localtime()) # year-month-day-hour-minute 589 | filename = path + name + "成交明细_" + m_time + ".xlsx" 590 | if os.path.exists(filename): 591 | os.remove(filename) 592 | for _ in range(3): 593 | try: 594 | wget.download(m_url, out=filename) 595 | break 596 | except: 597 | continue 598 | 599 | #filename = path + name + "成交明细_" + "2020_12_18" + ".xlsx" #补充操作 600 | 601 | con = 0 602 | def Deal_Xq(self, data, name): #忘记这么写的原因了,能跑咱就不动了 603 | con = self.con 604 | if self.stop == False: 605 | return 606 | if con < 4: 607 | if con == 0: 608 | con = con + 1 609 | t1 = threading.Thread(target=self.Deal_Xq_quote, args=(data, name, )) 610 | t1.start() 611 | t1.join() 612 | elif con == 1: 613 | con = con + 1 614 | t2 = threading.Thread(target=self.Deal_Xq_distribution, args=(data, name, )) 615 | t2.start() 616 | t2.join() 617 | elif con == 2: 618 | con = con + 1 619 | t3 = threading.Thread(target=self.Deal_Xq_query, args=(data, name, )) 620 | t3.start() 621 | t3.join() 622 | elif con == 3: 623 | con = con + 1 624 | t4 = threading.Thread(target=self.Deal_Xq_blocktrans, args=(data, name,)) 625 | t4.start() 626 | t4.join() 627 | #elif con < 5: 628 | self.con = self.con + 1 629 | 630 | def Analysis_date(self, s_url): 631 | for _ in range(3): 632 | try: 633 | self.xlsxdata = requests.get(s_url, headers=headers, timeout=(10, 30)) 634 | break 635 | except Exception as e: 636 | continue 637 | 638 | soup = BeautifulSoup(self.xlsxdata.text, "lxml") 639 | xlslist = soup.select('#historyData > div.bd > a:nth-child(1)') 640 | for xlsx in xlslist: 641 | return xlsx.get_text() 642 | 643 | def get_SelfStock(self): 644 | self.mkdir_stock() 645 | #url_list = list() 646 | name_list = dict() 647 | t = time.time() 648 | m_time = int(t) 649 | m_file_time = '' 650 | with open("Code.txt", "r", encoding='utf-8') as f: 651 | for line in f.readlines(): 652 | m_line = line.strip('\n') # 去掉列表中每一个元素的换行符 653 | if m_line == '': 654 | continue 655 | sep = '#' 656 | code = line.split(sep, 1)[0] 657 | if code != '': 658 | name = m_line.split(sep)[1] 659 | m_code = re.sub('[a-zA-Z]', "", code) #纯数字代码 SH000001 = 000001 660 | m_low_code = code.lower() #SH000001 = sh000001 661 | m_char = re.sub('[0-9]', "", code) #字母字符 SH0000001 = SH 662 | m_low_char = m_char.lower() #SH小写字符 663 | #雪球 664 | xq_url_quote = 'https://stock.xueqiu.com/v5/stock/quote.json?symbol={0}&extend=detail'.format(code) #个股信息 665 | # xq_url_quote = 'https://stock.xueqiu.com/v5/stock/batch/quote.json?extend=detail&is_delay_ft=1&is_delay_hk=0&symbol={}'.format(code) #个股信息 666 | xq_url_distrbution = 'https://stock.xueqiu.com/v5/stock/capital/distribution.json?symbol={}&_={}'.format(code, m_time) #今日流出 667 | xq_url_query = 'https://stock.xueqiu.com/v5/stock/capital/query.json?count=20&symbol={}&_={}'.format(code, m_time) #流出历史 668 | xq_url_blocktrans = 'https://stock.xueqiu.com/v5/stock/capital/blocktrans.json?symbol={}'.format(code) #大宗交易 669 | 670 | year_filetime = time.strftime("%Y", time.localtime()) # year-month-day-hour-minute 671 | #filetime = time.strftime("%Y%m%d", time.localtime()) # year-month-day-hour-minute 672 | num = 0 673 | if int(m_code) < 600000: 674 | num = 1 675 | #wyurl = 'http://quotes.money.163.com/cjmx/2021/20210929/1002241.xls' 676 | s_url = 'http://quotes.money.163.com/trade/cjmx_{0}.html'.format(m_code) 677 | self.filetime = self.Analysis_date(s_url) 678 | wyurl = '' 679 | if self.filetime != '': 680 | m_file_time = self.filetime 681 | wyfiletime = self.filetime.replace('-','') 682 | #'http://quotes.money.163.com/cjmx/2021/20210809/1300033.xls' 683 | wyurl = 'http://quotes.money.163.com/cjmx/{0}/{1}/{2}{3}.xls'.format(year_filetime, wyfiletime, num, m_code) 684 | 685 | #腾讯证券 686 | #tx_url_detail = 'http://stock.gtimg.cn/data/index.php?appn=detail&action=downlddoad&c={}&d={}'.format(m_low_code, filetime) #失效 687 | #tx_url_detail = 'http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c={}&d={}'.format(m_low_code, 20201218) #补充日期 失效 688 | 689 | name_list.setdefault(name, []) 690 | name_list[name].append(xq_url_quote) 691 | name_list[name].append(xq_url_distrbution) 692 | if wyurl != '': 693 | name_list[name].append(wyurl) 694 | name_list[name].append(xq_url_query) 695 | name_list[name].append(xq_url_blocktrans) 696 | self.filetime = '' 697 | 698 | url = 'https://xueqiu.com' 699 | session = requests.session() 700 | 701 | session.get(url, headers=headers) 702 | for name in name_list: 703 | self.stop = True 704 | path = self.get_path(name) 705 | for m_url in name_list[name]: 706 | resp = None 707 | res = "xueqiu" in m_url 708 | if res == True: 709 | for ll in range(3): 710 | try: 711 | resp = requests.get(m_url, headers=headers, timeout=120) 712 | if resp.status_code == 200: 713 | break 714 | except Exception as e: 715 | pass 716 | 717 | data = json.loads(resp.text) 718 | print(data) 719 | if data == None: 720 | continue 721 | 722 | self.Deal_Xq(data, name) 723 | res = False 724 | 725 | res = "quotes" in m_url 726 | if res == True: 727 | self.Download_Xlsx(m_url, path, name, m_file_time) 728 | res = False 729 | time.sleep(1) # 减速 730 | self.con = 0 731 | 732 | del name_list #释放 733 | self.filetime = '' 734 | 735 | 736 | def main(self, filename): 737 | #Stock = SelfStock(file_name) 738 | #Stock.get_filename() 739 | Stock.get_SelfStock() 740 | 741 | Stock = SelfStock() 742 | -------------------------------------------------------------------------------- /src/Sg_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | from queue import Queue 5 | 6 | headers = { 7 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 8 | } 9 | 10 | class SongGuo(object): 11 | def __init__(self): 12 | pass 13 | 14 | def request(self): 15 | self.url = 'http://www.songguocaijing.com/' 16 | for _ in range(3): 17 | try: 18 | self.data = requests.get(self.url, headers=headers, timeout=(10, 40)) 19 | break 20 | except: 21 | continue 22 | self.data.encoding = "utf-8" 23 | self.soup = BeautifulSoup(self.data.text, "lxml") 24 | 25 | 26 | def get_news(self): 27 | wb = load_workbook(self.xlsxname) 28 | sheet = wb.create_sheet("Sg") 29 | t_row = 1 30 | t_col = 1 31 | sheet.cell(row=t_row, column=t_col, value="松果财经") 32 | t_row = t_row + 1 33 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 34 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 35 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 36 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 37 | t_row = t_row + 1 38 | 39 | datalist = self.soup.find_all(class_='title-wp') 40 | da = '' 41 | da2 = '' 42 | da2 = self.soup.find_all(class_='article-description') 43 | m_queue = Queue(20) 44 | for des in da2: 45 | m_queue.put(des.get_text()) 46 | 47 | for da in datalist: 48 | da.find('a') 49 | for news in da: 50 | m_href = 'http://www.songguocaijing.com/' + news['href'] 51 | m_title = news['title'] 52 | sheet.cell(row=t_row, column=t_col, value=m_title) 53 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 54 | sheet.cell(row=t_row, column=t_col + 2, value=m_queue.get()) 55 | t_row = t_row + 1 56 | 57 | try: 58 | wb.save(self.xlsxname) 59 | except: 60 | print("Songguo Save Error") 61 | 62 | def main(self, file_name): 63 | self.xlsxname = file_name 64 | Sg.request() 65 | Sg.get_news() 66 | 67 | Sg = SongGuo() 68 | -------------------------------------------------------------------------------- /src/Sina_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | from openpyxl.styles import Font 5 | import datetime 6 | import time 7 | import json 8 | import threading 9 | 10 | """ 11 | https://finance.sina.com.cn/ 12 | http://finance.sina.com.cn/chanjing/ 13 | http://feed.mix.sina.com.cn/api/roll/get?pageid=164&lid=1694&num=10&page=1&callback=feedCardJsonpCallback&_=1611561556802 公司新闻 14 | http://feed.mix.sina.com.cn/api/roll/get?pageid=164&lid=1695&num=10&page=1&callback=feedCardJsonpCallback&_=1611561513495 产业新闻 15 | 16 | http://finance.sina.com.cn/china/ 17 | http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1687&num=10&page=1&callback=feedCardJsonpCallback&_=1611573471132 国内新闻 18 | http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1687&num=10&page=1&callback=feedCardJsonpCallback&_=1611573513741 宏观经济 19 | http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1689&num=10&page=1&callback=feedCardJsonpCallback&_=1611573537003 部委动态 20 | http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1690&num=10&page=1&callback=feedCardJsonpCallback&_=1611573555700 金融新闻 21 | http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1688&num=10&page=1&callback=feedCardJsonpCallback&_=1611573598249 地方经济 22 | """ 23 | 24 | headers = { 25 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 26 | } 27 | 28 | class SinaNews(object): 29 | def __init__(self): 30 | pass 31 | 32 | def request(self): 33 | self.url = 'https://finance.sina.com.cn/' 34 | 35 | for ll in range(3): 36 | try: 37 | self.data = requests.get(self.url, headers=headers, timeout=120) 38 | if self.data.status_code == 200: 39 | break 40 | except Exception as e: 41 | pass 42 | self.data.encoding = "utf-8" 43 | self.soup = BeautifulSoup(self.data.text, "lxml") 44 | 45 | 46 | def getTopNew(self): 47 | wb = load_workbook(self.xlsxname) 48 | sheet = wb.create_sheet("Sina") 49 | t_row = 1 50 | t_col = 1 51 | sheet.cell(row=t_row, column=t_col, value="新浪财经") 52 | t_row = t_row + 1 53 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 54 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 55 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 56 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 57 | t_row = t_row + 1 58 | 59 | datalist = self.soup.find_all(class_='fin_tabs0_c0') 60 | datal = None 61 | for datal in datalist: 62 | t = 0 #留着先 63 | 64 | for ds in datal: 65 | ds = datal.find_all('a') 66 | for m_data in ds: 67 | m_href = m_data['href'] 68 | m_title = m_data.get_text() 69 | if len(m_title) < 4: 70 | continue 71 | sheet.cell(row=t_row, column=t_col, value=m_title) 72 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 73 | t_row = t_row + 1 74 | break 75 | 76 | try: 77 | wb.save(self.xlsxname) 78 | except: 79 | print("SinaNews Save Error = getTopNew") 80 | 81 | def getStockNew(self): 82 | wb = load_workbook(self.xlsxname) 83 | sheet = wb.get_sheet_by_name("Sina") 84 | t_row = sheet.max_row + 3 85 | t_col = 1 86 | sheet.cell(row=t_row, column=t_col, value="证券新闻") 87 | t_row = t_row + 1 88 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 89 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 90 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 91 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 92 | t_row = t_row + 1 93 | 94 | datalist = self.soup.find_all(class_='m-p1-m-blk2') 95 | for dastl in datalist: 96 | t = 1 97 | 98 | for ds in dastl: 99 | ds = dastl.find_all('a') 100 | for m_data in ds: 101 | try: 102 | m_href = m_data['href'] 103 | m_title = m_data.get_text() 104 | if len(m_title) < 4: 105 | continue 106 | sheet.cell(row=t_row, column=t_col, value=m_title) 107 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 108 | t_row = t_row + 1 109 | except: 110 | continue 111 | break 112 | 113 | try: 114 | wb.save(self.xlsxname) 115 | except: 116 | print("SinaNews Save Error = getStockNew") 117 | 118 | 119 | def getIndustryNew(self): 120 | t = time.time() * 1000 121 | n_time = int(t) 122 | new_list = list() 123 | 124 | j_url1 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=164&lid=1694&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #公司新闻 125 | j_url2 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=164&lid=1695&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #产业新闻 126 | 127 | cn_url1 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=3231&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #财经top10 128 | cn_url2 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1686&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #国内新闻 129 | cn_url3 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1687&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #宏观经济 130 | cn_url4 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1689&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #部委动态 131 | cn_url5 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1690&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #金融新闻 132 | cn_url6 = 'http://feed.mix.sina.com.cn/api/roll/get?pageid=155&lid=1688&num=10&page=1&callback=feedCardJsonpCallback&_={}'.format(n_time) #地方新闻 133 | new_list = { 134 | "财经Top10": cn_url1, 135 | "公司新闻": j_url1, 136 | "产业新闻": j_url2, 137 | "国内新闻": cn_url2, 138 | "宏观经济": cn_url3, 139 | "部委动态": cn_url4, 140 | "金融新闻": cn_url5, 141 | "地方新闻": cn_url6, 142 | } 143 | for newname in new_list: 144 | m_url = new_list[newname] 145 | self.Deal_News(m_url, newname) 146 | 147 | 148 | def Deal_News(self, url, new_name): 149 | wb = load_workbook(self.xlsxname) 150 | sheet = wb.get_sheet_by_name("Sina") 151 | t_row = sheet.max_row + 2 152 | t_col = 1 153 | sheet.cell(row=t_row, column=t_col, value="{}".format(new_name)) 154 | t_row = t_row + 1 155 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 156 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 157 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 158 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 159 | t_row = t_row + 1 160 | 161 | data = None 162 | for ll in range(3): 163 | try: 164 | data = requests.get(url, headers=headers, timeout=120) 165 | if data.status_code == 200: 166 | break 167 | except Exception as e: 168 | pass 169 | t1 = '

try{feedCardJsonpCallback(' 170 | t2 = ');}catch(e){};

' 171 | soup = BeautifulSoup(data.text, "lxml") 172 | data = str(soup) 173 | data = data.replace(t1, "") 174 | data = data.replace(t2, "") 175 | json_str = json.loads(data) 176 | json_str = json_str['result']['data'] 177 | for m_data in json_str: 178 | m_href = m_data['url'] 179 | m_title = m_data['title'] 180 | tmp_m_time = m_data['ctime'] 181 | timeStamp = int(tmp_m_time) 182 | timeArray = time.localtime(timeStamp) 183 | m_time = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) 184 | 185 | sheet.cell(row=t_row, column=t_col, value=m_title) 186 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 187 | sheet.cell(row=t_row, column=t_col + 3, value=m_time) 188 | t_row = t_row + 1 189 | 190 | 191 | """ 192 | t_row = t_row + 2 193 | sheet.cell(row=t_row, column=t_col, value="产业新闻") 194 | t_row = t_row + 1 195 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 196 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 197 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 198 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 199 | t_row = t_row + 1 200 | 201 | data = requests.get(j_url2, headers=headers) 202 | soup = BeautifulSoup(data.text, "lxml") 203 | data = str(soup) 204 | m1 = '

try{feedCardJsonpCallback(' 205 | m2 = ');}catch(e){};

' 206 | data = data.replace(m1, "") 207 | data = data.replace(m2, "") 208 | json_str2 = json.loads(data) 209 | json_s = json_str2['result']['data'] 210 | for m_data in json_s: 211 | m_href = m_data['url'] 212 | m_title = m_data['title'] 213 | tmp_m_time = m_data['ctime'] 214 | timeStamp = int(tmp_m_time) 215 | timeArray = time.localtime(timeStamp) 216 | m_time = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) 217 | 218 | sheet.cell(row=t_row, column=t_col, value=m_title) 219 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 220 | sheet.cell(row=t_row, column=t_col + 3, value=m_time) 221 | t_row = t_row + 1 222 | """ 223 | try: 224 | wb.save(self.xlsxname) 225 | except: 226 | print("Sina getIndustryNew Save Error") 227 | 228 | def getCnNew(self): 229 | 230 | t = time.time() * 1000 231 | n_time = int(t) 232 | 233 | 234 | 235 | def main(self, file_name): 236 | self.xlsxname = file_name 237 | Sina.request() 238 | Sina.getTopNew() 239 | Sina.getStockNew() 240 | Sina.getIndustryNew() 241 | Sina.getCnNew() 242 | 243 | Sina = SinaNews() 244 | -------------------------------------------------------------------------------- /src/Ths_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | from openpyxl.styles import Font 5 | import json 6 | import time 7 | import threading 8 | 9 | headers = { 10 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 11 | } 12 | 13 | class TongHuaShun(object): 14 | def __init__(self): 15 | pass 16 | 17 | def request(self): 18 | self.url = 'http://www.10jqka.com.cn/' 19 | for ll in range(3): 20 | try: 21 | self.data = requests.get(self.url, headers=headers, timeout=120) 22 | if self.data.status_code == 200: 23 | break 24 | except Exception as e: 25 | pass 26 | 27 | self.data.encoding = "gbk" 28 | self.soup = BeautifulSoup(self.data.text, "lxml") 29 | 30 | #calendar 31 | calendar_time = time.strftime("%Y%m", time.localtime()) # year-month-day-hour-minute 32 | #self.url_calendar = 'http://stock.10jqka.com.cn/fincalendar.shtml#{}'.format(datatime) 33 | self.url_calendar = 'http://comment.10jqka.com.cn/tzrl/getTzrlData.php?callback=callback_dt&type=data&date={}'.format(calendar_time) 34 | 35 | for ll in range(3): 36 | try: 37 | self.data_calendar = requests.get(self.url_calendar, headers=headers, timeout=120) 38 | if self.data_calendar.status_code == 200: 39 | break 40 | except Exception as e: 41 | pass 42 | 43 | 44 | def Style(self): 45 | self.m_font = Font( 46 | size=12, 47 | bold=True, 48 | ) 49 | 50 | self.head_font = Font( 51 | size=14, 52 | bold=True, 53 | ) 54 | 55 | def getNew(self): 56 | wb = load_workbook(self.xlsxname) 57 | sheet = wb.create_sheet('Ths') 58 | datalist = self.soup.find_all(class_="item_txt") 59 | t_row = 1 60 | t_col = 1 61 | 62 | sheet.cell(row=t_row + 0, column=t_col + 0, value="同花顺财经") 63 | sheet.cell(row=t_row + 1, column=t_col + 0, value="新闻标题") 64 | sheet.cell(row=t_row + 1, column=t_col + 1, value="新闻链接") 65 | sheet.cell(row=t_row + 1, column=t_col + 2, value="新闻简介") 66 | sheet.cell(row=t_row + 1, column=t_col + 3, value="新闻时间") 67 | t_row = t_row + 2 68 | 69 | for news in datalist: 70 | newlist2 = news.select('p a') 71 | for m_new in newlist2: 72 | m_url = m_new['href'] 73 | m_title = m_new['title'] 74 | sheet.cell(row=t_row, column=t_col, value=m_title) 75 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 76 | t_row = t_row + 1 77 | try: 78 | wb.save(self.xlsxname) 79 | except Exception: 80 | print("THS Save Error = 1") 81 | 82 | def getInvestment(self): 83 | wb = load_workbook(self.xlsxname) 84 | sheet = wb.get_sheet_by_name('Ths') 85 | t_row = sheet.max_row 86 | 87 | datalist = self.soup.find_all(class_="content newhe") #投资机会上半部分 产经新闻 研报精选 88 | t_col = 1 89 | index = 0 90 | for newlist in datalist: 91 | #里面有个重复 加个判断去掉 92 | news = newlist.select('li a') 93 | for m_new in news: 94 | if index != 1: 95 | m_url = m_new['href'] 96 | m_title = m_new['title'] 97 | sheet.cell(row=t_row, column=t_col, value=m_title) 98 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 99 | t_row = t_row + 1 100 | index = index + 1 101 | try: 102 | wb.save(self.xlsxname) 103 | except Exception: 104 | print("THS Save Error = 2") 105 | 106 | def getInvestment2(self): 107 | wb = load_workbook(self.xlsxname) 108 | sheet = wb.get_sheet_by_name('Ths') 109 | t_row = sheet.max_row 110 | t_col = 1 111 | #投资机会后半部分获取 112 | datalist = self.soup.find_all(class_="last") 113 | 114 | i = 0 115 | for newlist in datalist: 116 | news = newlist.select('li a') 117 | for m_new in news: 118 | #这个分类筛选的结果重复的太多 但是数量是固定的 119 | if i >= 5: 120 | if i < 11: 121 | m_title = m_new.get_text() 122 | m_url = m_new['href'] 123 | sheet.cell(row=t_row, column=t_col, value=m_title) 124 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 125 | t_row = t_row + 1 126 | i = i + 1 127 | try: 128 | wb.save(self.xlsxname) 129 | except Exception: 130 | print("THS Save Error = 3") 131 | 132 | def get_Newspaper(self): 133 | url_Newspaper = 'http://stock.10jqka.com.cn/bktt_list/' 134 | data_paper = requests.get(url_Newspaper, headers=headers) 135 | soup_paper = BeautifulSoup(data_paper.text, "lxml") 136 | 137 | datalist = soup_paper.select('body > div.content-1200 > div.module-l.fl > div.list-con > ul > li:nth-child(1) > span > a') 138 | datalist2 = soup_paper.select('body > div.content-1200 > div.module-l.fl > div.list-con > ul > li:nth-child(1) > a') 139 | m_url = datalist[0]['href'] 140 | m_title = datalist[0]['title'] 141 | m_content = datalist2[0].get_text() + "del" 142 | m_content = m_content.replace("...del", "") 143 | 144 | wb = load_workbook(self.xlsxname) 145 | sheet = wb.get_sheet_by_name('Ths') 146 | t_row = sheet.max_row + 1 147 | t_col = 1 148 | 149 | sheet.cell(row=t_row + 1, column=t_col, value="报刊头条") #下一个函数省一次xlwt操作 (投资日历) 150 | t_row = t_row + 2 151 | sheet.cell(row=t_row, column=t_col, value=m_title) 152 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 153 | sheet.cell(row=t_row, column=t_col + 2, value=m_content) 154 | 155 | # 为下一个函数省一次xlwt操作 (投资日历) 156 | sheet.cell(row=t_row + 2, column=t_col, value="投资日历") 157 | sheet.cell(row=t_row + 3 ,column=t_col, value="会议事件") 158 | sheet.cell(row=t_row + 3, column=t_col + 1, value="会议地点") 159 | sheet.cell(row=t_row + 3, column=t_col + 2, value="会议时间") 160 | try: 161 | wb.save(self.xlsxname) 162 | except Exception: 163 | print("THS Save Error = 4") 164 | 165 | threadLock = threading.Lock() 166 | def dealjson(self, json): #时间 事件 地点 json问题相关板块顺序是乱序 就不加了 167 | self.threadLock.acquire() 168 | wb = load_workbook(self.xlsxname) 169 | sheet = wb.get_sheet_by_name('Ths') 170 | t_row = sheet.max_row + 1 171 | t_col = 1 172 | 173 | for json_event in json['events']: 174 | m_event = json_event[0] 175 | m_place = json_event[2] 176 | sheet.cell(row=t_row, column=t_col, value=m_event) 177 | sheet.cell(row=t_row, column=t_col + 1, value=m_place) 178 | m_date = json['date'] 179 | m_week = json['week'] 180 | sheet.cell(row=t_row, column=t_col + 2, value=m_date + "-" + m_week) 181 | t_row = t_row + 1 182 | try: 183 | wb.save(self.xlsxname) 184 | self.threadLock.release() 185 | except Exception: 186 | self.threadLock.release() 187 | print("THS Save Error = 5") 188 | 189 | 190 | def get_Calendar(self): #投资日历 191 | data = self.data_calendar.text + "del" 192 | data = data.replace("callback_dt(", "") 193 | data = data.replace(");del", "") 194 | json_str = json.loads(data) 195 | t = 0 196 | #pool = ThreadPoolExecutor(max_workers=2) 197 | for m_json in json_str['data']: 198 | #future1 = pool.submit(self.dealjson, m_json) 199 | t1 = threading.Thread(target=self.dealjson, args=(m_json, )) 200 | t1.start() 201 | t1.join() 202 | 203 | def main(self, file_name): 204 | self.xlsxname = file_name 205 | Ths.request() 206 | Ths.getNew() 207 | Ths.getInvestment() 208 | Ths.getInvestment2() 209 | Ths.get_Newspaper() 210 | Ths.get_Calendar() 211 | 212 | Ths = TongHuaShun() 213 | -------------------------------------------------------------------------------- /src/Tzj_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | import re 5 | 6 | headers = { 7 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15', 8 | } 9 | 10 | class Touzijie(object): 11 | def __init__(self): 12 | pass 13 | 14 | def request(self): 15 | self.url = 'https://www.pedaily.cn' 16 | for ll in range(3): 17 | try: 18 | self.data = requests.get(self.url, headers=headers, timeout=120) 19 | if self.data.status_code == 200: 20 | break 21 | except Exception as e: 22 | pass 23 | self.data.encoding = "utf-8" 24 | self.soup = BeautifulSoup(self.data.text, "lxml") 25 | 26 | def get_topnews(self): 27 | wb = load_workbook(self.xlsxname) 28 | sheet = wb.create_sheet("Tzj") 29 | t_row = 1 30 | t_col = 1 31 | 32 | sheet.cell(row=t_row, column=t_col, value="每日TOP5") 33 | t_row = t_row + 1 34 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 35 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 36 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 37 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 38 | t_row = t_row + 1 39 | 40 | datalist = self.soup.select('#box-fix-content > div.tab-content > ul:nth-child(1)') 41 | for data in datalist: 42 | news = data.find_all('a') 43 | for m_new in news: 44 | m_href = m_new['href'] 45 | m_title = m_new.get_text() 46 | sheet.cell(row=t_row, column=t_col, value=m_title) 47 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 48 | t_row = t_row + 1 49 | 50 | try: 51 | wb.save(self.xlsxname) 52 | except Exception: 53 | print("Tzj Save Error = 1") 54 | 55 | def get_news(self): 56 | wb = load_workbook(self.xlsxname) 57 | sheet = wb.get_sheet_by_name("Tzj") 58 | t_row = sheet.max_row + 2 59 | t_col = 1 60 | sheet.cell(row=t_row, column=t_col, value="最新资讯") 61 | t_row = t_row + 1 62 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 63 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 64 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 65 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 66 | t_row = t_row + 1 67 | datalist = self.soup.find_all(class_='news-list news-list-bottom news-list-special') 68 | for data in datalist: 69 | news = data.find_all(class_='txt') 70 | for m_news in news: 71 | m_news = m_news.find_all('h3') 72 | pattern = re.compile(r'((https|http)?:\/\/)[^\s]+[^" t]') 73 | searchObj = re.search(r'(.*)target="_blank">(.*?)', str(m_news), re.M | re.I) 74 | m_href = pattern.search(str(m_news)).group() 75 | m_title = searchObj.group(2) 76 | sheet.cell(row=t_row, column=t_col, value=m_title) 77 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 78 | t_row = t_row + 1 79 | try: 80 | wb.save(self.xlsxname) 81 | except Exception: 82 | print("Tzj Save Error = 2") 83 | 84 | def get_Instantnews(self): 85 | wb = load_workbook(self.xlsxname) 86 | sheet = wb.get_sheet_by_name("Tzj") 87 | t_row = sheet.max_row + 2 88 | t_col = 1 89 | sheet.cell(row=t_row, column=t_col, value="即时快讯") 90 | t_row = t_row + 1 91 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 92 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 93 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 94 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 95 | t_row = t_row + 1 96 | datalist = self.soup.find_all(class_='list-time hot-online') 97 | 98 | for trtag in datalist: 99 | data = trtag.find_all('li') # 在每个tr标签下,查找所有的td标签 100 | for news in data: 101 | m_href = news['data-url'] 102 | m_title = news['data-title'] 103 | sheet.cell(row=t_row, column=t_col, value=m_title) 104 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 105 | t_row = t_row + 1 106 | 107 | try: 108 | wb.save(self.xlsxname) 109 | except Exception: 110 | print("Tzj Save Error = 2") 111 | 112 | def get_invest(self): 113 | datalist = self.soup.find_all(class_='list-invest') 114 | print(datalist) 115 | 116 | def get_ipo(self): 117 | datalist = self.soup.find_all(class_='list-ipo') 118 | print(datalist) 119 | 120 | 121 | def main(self, file_name): 122 | self.xlsxname = file_name 123 | try: 124 | Tzj.request() 125 | Tzj.get_topnews() 126 | Tzj.get_news() 127 | Tzj.get_Instantnews() 128 | except Exception: 129 | pass 130 | 131 | 132 | Tzj = Touzijie() -------------------------------------------------------------------------------- /src/UA.py: -------------------------------------------------------------------------------- 1 | USER_AGENT_LIST = [ 2 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", 3 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)", 4 | "Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", 5 | "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)", 6 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)", 7 | "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)", 8 | "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)", 9 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)", 10 | "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6", 11 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1", 12 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0", 13 | "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5", 14 | "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6", 15 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", 16 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20", 17 | "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52", 18 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11", 19 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER", 20 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)", 21 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)", 22 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER", 23 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)", 24 | "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)", 25 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)", 26 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; 360SE)", 27 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)", 28 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)", 29 | "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1", 30 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1", 31 | "Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", 32 | "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b13pre) Gecko/20110307 Firefox/4.0b13pre", 33 | "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0", 34 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11", 35 | "Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10", 36 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", 37 | ] 38 | import random #这个文件的UA用不用都不影响 39 | USER_AGENT = random.choice(USER_AGENT_LIST) 40 | # 构造请求头 41 | headers = {'user-agent': USER_AGENT} -------------------------------------------------------------------------------- /src/Wy_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | import os 4 | from openpyxl import load_workbook, Workbook 5 | from openpyxl.styles import Font 6 | import json 7 | import time 8 | import threading 9 | 10 | """ 11 | https://www.pynote.net/archives/2229 12 | font(字体类):字号、字体颜色、下划线等 13 | fill(填充类):颜色等 14 | border(边框类):设置单元格边框 15 | alignment(位置类):对齐方式 16 | number_format(格式类):数据格式 17 | protection(保护类):写保护 18 | """ 19 | 20 | headers = { 21 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 22 | } 23 | 24 | class WangYi(object): 25 | def __init__(self): 26 | pass 27 | 28 | def request(self): 29 | #new 30 | self.url = 'https://money.163.com/' 31 | for ll in range(3): 32 | try: 33 | self.data = requests.get(self.url, headers=headers, timeout=120) 34 | if self.data.status_code == 200: 35 | break 36 | except Exception as e: 37 | pass 38 | 39 | self.soup = BeautifulSoup(self.data.text, "lxml") 40 | self.time = time.time() 41 | 42 | def Style(self): 43 | self.m_font = Font(name="微软雅黑",size=15,bold=True,italic=True,color="FF0000") 44 | self.head_font = Font(name="微软雅黑",size=20,bold=True,italic=True,color="FF0000") 45 | 46 | 47 | def getTopNew(self): 48 | datalist = self.soup.select("ul li h2") 49 | wb = Workbook() 50 | ws = wb['Sheet'] 51 | wb.remove(ws) 52 | sheet = wb.create_sheet("Wy") 53 | """ 54 | alignment = xlwt.Alignment 55 | alignment.horz = xlwt.Alignment.HORZ_CENTER 56 | alignment.vert = xlwt.Alignment.VERT_CENTER 57 | style2 = xlwt.XFStyle() 58 | style2.alignment = alignment 59 | """ 60 | t_row = 6 61 | t_col = 1 62 | sheet.cell(row=t_row, column=t_col, value="网易财经") 63 | t_row = t_row + 1 64 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 65 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 66 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 67 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 68 | t_row = t_row + 1 69 | 70 | for li in datalist: 71 | url = li.find('a')['href'] 72 | title = li.get_text() 73 | sheet.cell(row=t_row, column=t_col, value=title) 74 | sheet.cell(row=t_row, column=t_col + 1, value=url) 75 | t_row = t_row + 1 76 | try: 77 | wb.save(self.xlsxname) 78 | except Exception: 79 | print("Wy Save Error = 1") 80 | 81 | def getlist2(self): 82 | datalist2 = self.soup.find_all(class_='topnews_nlist topnews_nlist2') 83 | 84 | wb = load_workbook(self.xlsxname) 85 | sheet = wb.get_sheet_by_name('Wy') 86 | t_row = sheet.max_row # 获得行数 87 | t_col = 1 88 | for tp in datalist2: 89 | datalist3 = tp.select("li h3") 90 | for tn in datalist3: 91 | url = tn.find('a')['href'] 92 | title = tn.get_text() 93 | sheet.cell(row=t_row, column=t_col, value=title) 94 | sheet.cell(row=t_row, column=t_col + 1, value=url) 95 | t_row = t_row + 1 96 | try: 97 | wb.save(self.xlsxname) 98 | except: 99 | print("Wangyi Save Error = 2") 100 | 101 | def getstock(self): 102 | #stock 103 | stockurl = 'https://money.163.com/stock' 104 | stockdata = requests.get(stockurl, headers=headers) 105 | soup = BeautifulSoup(stockdata.text, "lxml") 106 | stockl = soup.select('#stock2016_wrap > div > div.stock2016_content > div.idx_main.common_wrap.clearfix > div.news_main > div.news_main_wrap > div.topnews > div.topnews_first > h2 > a') 107 | top_url = stockl[0]['href'] 108 | top_title = stockl[0].get_text() 109 | 110 | wb = load_workbook(self.xlsxname) 111 | sheet = wb.get_sheet_by_name('Wy') 112 | t_row = sheet.max_row # 获得行数 113 | t_col = 1 114 | 115 | stocknewlist = soup.find_all(class_='topnews_list') 116 | for s_new in stocknewlist: 117 | news = s_new.find_all('a') 118 | for tn in news: 119 | t_url = tn['href'] 120 | t_title = tn.get_text() 121 | sheet.cell(row=t_row, column=t_col, value=t_title) 122 | sheet.cell(row=t_row, column=t_col + 1, value=t_url) 123 | t_row = t_row + 1 124 | try: 125 | wb.save(self.xlsxname) 126 | except: 127 | print("Wangyi Save Error = 4") 128 | 129 | threadLock = threading.Lock() 130 | def get_num(self, num, row, if_write): 131 | self.threadLock.acquire() 132 | 133 | num_price = num['price'] 134 | num_open = num['open'] 135 | num_updown = num['updown'] 136 | num_high = num['high'] 137 | num_low = num['low'] 138 | num_yestclose = num['yestclose'] 139 | num_percent = num['percent'] #num_percent 不直接写入 140 | num_update = num['update'] 141 | m_percent = num_percent * 10000 #-0.020937 -%2.09 142 | percent = int(m_percent) /100 143 | 144 | wb = load_workbook(self.xlsxname) 145 | sheet = wb.get_sheet_by_name('Wy') 146 | t_col = 1 147 | 148 | if if_write == True: 149 | t_row = 1 150 | sheet.cell(row=t_row, column=t_col, value='大盘指数') 151 | sheet.cell(row=t_row, column=t_col + 1, value='当前价位') 152 | sheet.cell(row=t_row, column=t_col + 2, value='今日涨幅') 153 | sheet.cell(row=t_row, column=t_col + 3, value='涨跌价格') 154 | sheet.cell(row=t_row, column=t_col + 4, value='开盘价位') 155 | sheet.cell(row=t_row, column=t_col + 5, value='今日最高') 156 | sheet.cell(row=t_row, column=t_col + 6, value='今日最低') 157 | sheet.cell(row=t_row, column=t_col + 7, value='昨日收盘') 158 | sheet.cell(row=t_row, column=t_col + 8, value='更新时间') 159 | sheet.cell(row=t_row + 2, column=t_col, value='深证成指') 160 | sheet.cell(row=t_row + 1, column=t_col, value='上证指数') 161 | sheet.cell(row=t_row + 3, column=t_col, value='沪深300') 162 | t_row = t_row + 1 163 | 164 | sheet.cell(row=row, column=2, value=num_price) 165 | sheet.cell(row=row, column=3, value=str(percent) + "%") 166 | sheet.cell(row=row, column=4, value=num_updown) 167 | sheet.cell(row=row, column=5, value=num_open) 168 | sheet.cell(row=row, column=6, value=num_high) 169 | sheet.cell(row=row, column=7, value=num_low) 170 | sheet.cell(row=row, column=8, value=num_yestclose) 171 | sheet.cell(row=row, column=9, value=num_update) 172 | try: 173 | wb.save(self.xlsxname) 174 | self.threadLock.release() 175 | except: 176 | self.threadLock.release() 177 | print("Wangyi Save Error = 5") 178 | 179 | 180 | def getindex(self): 181 | #index 182 | indexurl = 'http://api.money.126.net/data/feed/1399001,1399300,0000001,HSRANK_COUNT_SHA,HSRANK_COUNT_SZA,HSRANK_COUNT_SH3?callback=ne_{}&[object%20Object]'.format(int(self.time)) 183 | indexdata = requests.get(indexurl, headers=headers) 184 | #soup = BeautifulSoup(self.indexdata.text,) 185 | data = indexdata.text + "del" 186 | time = int(self.time) 187 | data = data.replace('ne_' + str(time) + '(', '') 188 | data = data.replace(');del', '') 189 | #json_d = json.dumps(data) # 编码 190 | json_str = json.loads(data) # 解码 191 | 192 | if_write = True 193 | n_data1 = json_str['0000001'] #上证指数_0000001 194 | n_data2 = json_str['1399001'] #深证成指_1399001 195 | n_data3 = json_str['1399300'] #沪深300_1399300 196 | t1 = threading.Thread(target=self.get_num, args=(n_data1, 2, if_write, )) 197 | t1.start() 198 | if_write = False 199 | t1.join() 200 | t2 = threading.Thread(target=self.get_num, args=(n_data2, 3, if_write, )) 201 | t3 = threading.Thread(target=self.get_num, args=(n_data3, 4, if_write, )) 202 | t2.start() 203 | t3.start() 204 | t2.join() 205 | t3.join() 206 | #self.get_num(n2, 2, if_write) 207 | #self.get_num(n3, 3, if_write) 208 | 209 | def get_bu(self, soup, if_write): 210 | wb = load_workbook(self.xlsxname) 211 | sheet = wb.get_sheet_by_name('Wy') 212 | t_row = sheet.max_row + 1 213 | t_col = 1 214 | 215 | if if_write == True: 216 | sheet.cell(row=t_row + 1, column=t_col, value="市场资讯") 217 | sheet.cell(row=t_row + 2, column=t_col, value="新闻标题") 218 | sheet.cell(row=t_row + 2, column=t_col + 1, value="新闻链接") 219 | sheet.cell(row=t_row + 2, column=t_col + 2, value="新闻简介") 220 | sheet.cell(row=t_row + 2, column=t_col + 3, value="新闻时间") 221 | t_row = t_row + 3 # 已经使用多少行 222 | 223 | datalist1 = soup.find_all(class_='list_item clearfix') 224 | for Newslist in datalist1: 225 | News = Newslist.find_all(class_='item_top') 226 | for m_new in News: 227 | m_new1 = m_new.find('a') 228 | m_new2 = m_new.find(class_='time') 229 | m_title = m_new1.get_text() 230 | m_url = m_new1['href'] 231 | m_time = m_new2.get_text() 232 | sheet.cell(row=t_row, column=t_col, value=m_title) 233 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 234 | sheet.cell(row=t_row, column=t_col + 3, value=m_time) 235 | t_row = t_row + 1 236 | try: 237 | wb.save(self.xlsxname) 238 | except: 239 | print("Wangyi Save Error = 6") 240 | 241 | 242 | def getBusiness(self): #市场资讯 获取两页 243 | bu_url = 'http://money.163.com/special/00251LR5/cpznList.html' 244 | bu_url2 = 'http://money.163.com/special/00251LR5/cpznList_02.html' #第二页 245 | 246 | bu_data1 = requests.get(bu_url, headers=headers) 247 | soup1 = BeautifulSoup(bu_data1.text, "lxml") 248 | 249 | bu_data2 = requests.get(bu_url2, headers=headers) 250 | soup2 = BeautifulSoup(bu_data2.text, "lxml") 251 | 252 | if_write = True 253 | t1 =threading.Thread(target=self.get_bu, args=(soup1, if_write, )) 254 | t1.start() 255 | if_write = False 256 | t1.join() 257 | t2 =threading.Thread(target=self.get_bu, args=(soup1, if_write, )) 258 | t2.start() 259 | #self.get_bu(soup2, if_write) 260 | 261 | 262 | def get_Indu(self, soup, if_write): 263 | wb = load_workbook(self.xlsxname) 264 | sheet = wb.get_sheet_by_name('Wy') 265 | t_row = sheet.max_row + 1 266 | t_col = 1 267 | if if_write == True: 268 | sheet.cell(row=t_row + 1, column=t_col, value="行业板块") 269 | sheet.cell(row=t_row + 2, column=t_col, value="新闻标题") 270 | sheet.cell(row=t_row + 2, column=t_col + 1, value="新闻链接") 271 | sheet.cell(row=t_row + 2, column=t_col + 2, value="新闻简介") 272 | sheet.cell(row=t_row + 2, column=t_col + 3, value="新闻时间") 273 | t_row = t_row + 3 274 | 275 | datalist = soup.find_all(class_="col_l") 276 | for Newslist in datalist: 277 | News = Newslist.find_all(class_="list_item clearfix") 278 | for newlist in News: 279 | news = newlist.find_all(class_="item_top") 280 | for new in news: 281 | m_new = new.select('h2 a') 282 | m_url = m_new[0]['href'] 283 | m_title = m_new[0].get_text() 284 | m_new2 = new.select('p span') 285 | m_time = m_new2[0].get_text() 286 | sheet.cell(row=t_row, column=t_col, value=m_title) 287 | sheet.cell(row=t_row, column=t_col + 1, value=m_url) 288 | sheet.cell(row=t_row, column=t_col + 3, value=m_time) 289 | t_row = t_row + 1 290 | try: 291 | wb.save(self.xlsxname) 292 | except Exception: 293 | print("Wangyi Save Error = 7") 294 | 295 | def getIndustry(self): #行业资讯 前两页 296 | url = 'http://money.163.com/special/00251LJV/hyyj.html' 297 | url2 = 'http://money.163.com/special/00251LJV/hyyj_02.html' 298 | 299 | Industry_data1 = requests.get(url, headers=headers) 300 | soup1 = BeautifulSoup(Industry_data1.text, "lxml") 301 | Industry_data2 = requests.get(url2, headers=headers) 302 | soup2 = BeautifulSoup(Industry_data2.text, "lxml") 303 | if_write = True 304 | t1 = threading.Thread(target=self.get_Indu, args=(soup1, if_write, )) 305 | t1.start() 306 | if_write = False 307 | t1.join() 308 | t2 = threading.Thread(target=self.get_Indu, args=(soup2, if_write, )) 309 | t2.start() 310 | t2.join() 311 | #self.get_Indu(soup2, if_write) 312 | 313 | def create_file(self, filename): 314 | wb = Workbook() 315 | ws = wb['Sheet'] 316 | wb.remove(ws) 317 | sheet = wb.create_sheet("Wy") 318 | try: 319 | wb.save(filename) 320 | except Exception: 321 | print("Wy create_error = 1") 322 | 323 | def main(self, file_name): 324 | self.xlsxname = file_name 325 | Wy.request() 326 | Wy.getTopNew() 327 | Wy.getlist2() 328 | #stock 329 | Wy.getstock() 330 | Wy.getindex() # 主页原创栏目右边 331 | Wy.getBusiness() 332 | Wy.getIndustry() 333 | 334 | Wy = WangYi() 335 | -------------------------------------------------------------------------------- /src/Xhs_Finance.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | from openpyxl import load_workbook 4 | 5 | headers = { 6 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 7 | } 8 | 9 | class XinHuaNet(object): 10 | def __init__(self): 11 | pass 12 | 13 | def request(self): 14 | self.url = 'http://www.xinhuanet.com/fortunepro/' 15 | for ll in range(3): 16 | try: 17 | self.data = requests.get(self.url, headers=headers, timeout=120) 18 | if self.data.status_code == 200: 19 | break 20 | except Exception as e: 21 | pass 22 | 23 | self.data.encoding = "utf-8" 24 | self.soup = BeautifulSoup(self.data.text, "lxml") 25 | 26 | 27 | def getTopNew(self): 28 | wb = load_workbook(self.xlsxname) 29 | sheet = wb.create_sheet("Xhs") 30 | t_row = 1 31 | t_col = 1 32 | 33 | sheet.cell(row=t_row, column=t_col, value="财经TOP10") 34 | t_row = t_row + 1 35 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 36 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 37 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 38 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 39 | t_row = t_row + 1 40 | 41 | datalist = self.soup.find_all(class_='cjtop') 42 | for newlist in datalist: 43 | news = newlist.find_all('a') 44 | for m_new in news: 45 | m_href = m_new['href'] 46 | m_title = m_new.get_text() 47 | sheet.cell(row=t_row, column=t_col, value=m_title) 48 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 49 | t_row = t_row + 1 50 | 51 | try: 52 | wb.save(self.xlsxname) 53 | except Exception: 54 | print("Xhs Save Error = 1") 55 | 56 | def getnews(self): 57 | wb = load_workbook(self.xlsxname) 58 | sheet = wb.get_sheet_by_name("Xhs") 59 | t_row = sheet.max_row + 2 60 | t_col = 1 61 | sheet.cell(row=t_row, column=t_col, value="财经新闻") 62 | t_row = t_row + 1 63 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 64 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 65 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 66 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 67 | t_row = t_row + 1 68 | datalist = self.soup.find_all(class_='xpage-content-list') 69 | for data in datalist: 70 | news = data.find_all('a') 71 | for m_new in news: 72 | m_href = m_new['href'] 73 | m_title = m_new.get_text() 74 | if m_title == "": 75 | continue 76 | sheet.cell(row=t_row, column=t_col, value=m_title) 77 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 78 | t_row = t_row + 1 79 | try: 80 | wb.save(self.xlsxname) 81 | except Exception: 82 | print("Xhs Save Error = 2") 83 | 84 | 85 | def get_research_report(self): 86 | wb = load_workbook(self.xlsxname) 87 | sheet = wb.get_sheet_by_name("Xhs") 88 | t_row = sheet.max_row + 2 89 | t_col = 1 90 | sheet.cell(row=t_row, column=t_col, value="行业研报") 91 | t_row = t_row + 1 92 | sheet.cell(row=t_row, column=t_col, value="新闻标题") 93 | sheet.cell(row=t_row, column=t_col + 1, value="新闻链接") 94 | sheet.cell(row=t_row, column=t_col + 2, value="新闻简介") 95 | sheet.cell(row=t_row, column=t_col + 3, value="新闻时间") 96 | t_row = t_row + 1 97 | datalist = self.soup.find_all(class_='rtlist') 98 | for data in datalist: 99 | news = data.find_all('a') 100 | for m_new in news: 101 | m_href = m_new['href'] 102 | m_title = m_new.get_text() 103 | if len(m_title) <= 4: 104 | continue 105 | sheet.cell(row=t_row, column=t_col, value=m_title) 106 | sheet.cell(row=t_row, column=t_col + 1, value=m_href) 107 | t_row = t_row + 1 108 | 109 | try: 110 | wb.save(self.xlsxname) 111 | except Exception: 112 | print("Xhs Save Error = 3") 113 | 114 | 115 | def main(self, file_name): 116 | self.xlsxname = file_name 117 | Xhs.request() 118 | Xhs.getTopNew() 119 | Xhs.getnews() 120 | Xhs.get_research_report() 121 | 122 | 123 | Xhs = XinHuaNet() 124 | -------------------------------------------------------------------------------- /src/Xq_Community.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | import xlrd, xlwt 4 | import xlutils 5 | import json 6 | from requests.cookies import RequestsCookieJar 7 | 8 | headers = { 9 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36', 10 | #'Cookie': 'xqat=3e14cc861fdd960a5d84e7316165286b1bfeafe3;', 11 | } 12 | 13 | class XueQiu(object): 14 | def __init__(self, file_name): 15 | self.xlsxname = file_name 16 | 17 | 18 | def Style(self): 19 | font = xlwt.Font() # 内容字体 20 | font2 = xlwt.Font() # 标题字体 21 | font3 = xlwt.Font() # 指数 22 | font.height = 20 * 11 23 | font2.height = 20 * 12 24 | font2.bold = True 25 | font3.height = 20 * 13 26 | self.style = xlwt.XFStyle() #标题 链接字体 27 | self.style_head = xlwt.XFStyle() #类别列字体 28 | self.style_index = xlwt.XFStyle() #指数字体 29 | 30 | self.style.font = font 31 | self.style_head.font = font2 32 | self.style_index.font = font3 33 | 34 | def Today(self): 35 | url = 'https://xueqiu.com/' 36 | session = requests.session() 37 | data = session.get(url, headers=headers) 38 | soup = BeautifulSoup(data.text, "lxml") 39 | """ 40 | #取不到链接 只有json 后面考虑加不加入 41 | #url = xueqiu.com 42 | #data_url = xueqiu.com/today 43 | session = requests.session() 44 | session.get(url, headers=headers) 45 | resp = session.get(data_url, headers=headers).json() 46 | for items in resp['items']: 47 | title = items['original_status']['title'] 48 | description = items['original_status']['description'] 49 | keyword = items['original_status']['text'] 50 | 51 | def get_SelfStock(self): 52 | url_list = list() 53 | with open("Code.txt", "r") as f: 54 | for line in f.readlines(): 55 | line = line.strip('\n') # 去掉列表中每一个元素的换行符 56 | sep = '#' 57 | line = line.split(sep, 1)[0] 58 | if line != '': 59 | #url = 'https://xueqiu.com/S/{}'.format(line) 60 | url = 'https://stock.xueqiu.com/v5/stock/batch/quote.json?extend=detail&is_delay_ft=1&is_delay_hk=0&symbol={}'.format(line) 61 | url_list.append(url) 62 | 63 | url = 'https://xueqiu.com' 64 | session = requests.session() 65 | session.get(url, headers=headers) 66 | for url in url_list: 67 | resp = session.get(url, headers=headers) 68 | data = json.loads(resp.text) 69 | self.Deal_Xq_data() 70 | print(data) 71 | #data = requests.get(url, headers=headers) 72 | 73 | """ 74 | 75 | def main(self, file_name): 76 | Xq = XueQiu(file_name) 77 | Xq.Style() 78 | #Xq.Today() 79 | #Xq.get_SelfStock() 80 | 81 | -------------------------------------------------------------------------------- /src/search_us.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import os 4 | import time 5 | 6 | """ 7 | POST https://www.en 8 | tobit.cn/trending/top/getWeiboRankSearch.do HTTP/1.1 9 | Host: www.entobit.cn 10 | Connection: keep-alive 11 | Content-Length: 33 12 | sec-ch-ua: "Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109" 13 | Accept: application/json, text/plain, */* 14 | Content-Type: application/x-www-form-urlencoded 15 | sec-ch-ua-mobile: ?0 16 | type: restful 17 | User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 18 | sec-ch-ua-platform: "Windows" 19 | Origin: https://www.entobit.cn 20 | Sec-Fetch-Site: same-origin 21 | Sec-Fetch-Mode: cors 22 | Sec-Fetch-Dest: empty 23 | Referer: https://www.ent 24 | obit.cn/hot-search/nav/home?accessToken=Cjr8dOf3BVcz6kQELQ24/SHCztOETa%2BGJuB%2BR4c2SaWErDW6BR7ZBuKo5idM1TWHQ2YHNf6GjPn6Vxb971zAPw==&bindPhone=false&isIos=&isWx= 25 | Accept-Encoding: gzip, deflate, br 26 | Accept-Language: zh-CN,zh;q=0.9 27 | 28 | keyword=%E7%BE%8E%E5%85%83&from=1 29 | 30 | HTTP/1.1 200 OK 31 | Server: nginx/1.18.0 32 | Date: Thu, 11 May 2023 08:52:42 GMT 33 | Content-Type: application/json;charset=UTF-8 34 | Content-Length: 6209 35 | Connection: keep-alive 36 | 37 | {"rows":[{"duration":9840,"searchNums":29164,"keywords":"莫兰特损失4000万美元","updateTime":1683794940,"type":"realTimeHotSpots","topRanking":21,"url":"https://s.weibo.com/weibo?q=%23%E8%8E%AB%E5%85%B0%E7%89%B9%E6%8D%9F%E5%A4%B14000%E4%B8%87%E7%BE%8E%E5%85%83%23","firstRankingTime":1683785700},{"duration":82260,"searchNums":1494363,"keywords":"特朗普性侵罪成 向女作家赔500万美元","updateTime":1683761340,"type":"toutiao","topRanking":1,"url":"https://m.toutiao.com/search/?keyword=特朗普性侵罪成 向女作家赔500万美元&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683675000},{"duration":3720,"searchNums":37860,"keywords":"美国宣布再向乌提供12亿美元军援","updateTime":1683737160,"type":"toutiao","topRanking":35,"url":"https://m.toutiao.com/search/?keyword=美国宣布再向乌提供12亿美元军援&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683733140},{"duration":6480,"searchNums":283486,"keywords":"外媒:“去美元化”已成当下趋势","updateTime":1683712200,"type":"toutiao","topRanking":8,"url":"https://m.toutiao.com/search/?keyword=外媒:“去美元化”已成当下趋势&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683700200},{"duration":12180,"searchNums":8581651,"keywords":"美将向乌提供12亿美元军事援助","updateTime":1683676080,"type":"kwai","topRanking":1,"url":"","firstRankingTime":1683614220},{"duration":18660,"searchNums":22312,"keywords":"崩铁希儿吸金近三千万美元","updateTime":1683606420,"type":"realTimeHotSpots","topRanking":21,"url":"https://s.weibo.com/weibo?q=%23%E5%B4%A9%E9%93%81%E5%B8%8C%E5%84%BF%E5%90%B8%E9%87%91%E8%BF%91%E4%B8%89%E5%8D%83%E4%B8%87%E7%BE%8E%E5%85%83%23","firstRankingTime":1683587820},{"duration":2460,"searchNums":164917,"keywords":"沙特将向苏丹提供价值1亿美元援助","updateTime":1683527040,"type":"toutiao","topRanking":31,"url":"https://m.toutiao.com/search/?keyword=沙特将向苏丹提供价值1亿美元援助&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683517140},{"duration":5100,"searchNums":2465723,"keywords":"美媒:好莱坞编剧罢工损失超100亿美元","updateTime":1683526800,"type":"baidu","topRanking":6,"url":"https://www.baidu.com/s?wd=%E7%BE%8E%E5%AA%92%3A%E5%A5%BD%E8%8E%B1%E5%9D%9E%E7%BC%96%E5%89%A7%E7%BD%A2%E5%B7%A5%E6%8D%9F%E5%A4%B1%E8%B6%85100%E4%BA%BF%E7%BE%8E%E5%85%83&sa=fyb_news&rsv_dl=fyb_news","firstRankingTime":1683506100},{"duration":58020,"searchNums":2320820,"keywords":"截至4月末外汇储备规模32048亿美元","updateTime":1683512820,"type":"toutiao","topRanking":2,"url":"https://m.toutiao.com/search/?keyword=截至4月末外汇储备规模32048亿美元&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683429660},{"duration":11160,"searchNums":52850,"keywords":"2023年全球票房破100亿美元","updateTime":1683455700,"type":"toutiao","topRanking":8,"url":"https://m.toutiao.com/search/?keyword=2023年全球票房破100亿美元&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683442080},{"duration":20520,"searchNums":24139,"keywords":"国际奥委会向中国奥委会捐赠1040万美元","updateTime":1683455640,"type":"realTimeHotSpots","topRanking":21,"url":"https://s.weibo.com/weibo?q=%23%E5%9B%BD%E9%99%85%E5%A5%A5%E5%A7%94%E4%BC%9A%E5%90%91%E4%B8%AD%E5%9B%BD%E5%A5%A5%E5%A7%94%E4%BC%9A%E6%8D%90%E8%B5%A01040%E4%B8%87%E7%BE%8E%E5%85%83%23","firstRankingTime":1683434700},{"duration":480,"searchNums":137737,"keywords":"巴菲特:美元未来不一定是储备货币","updateTime":1683436680,"type":"toutiao","topRanking":43,"url":"https://m.toutiao.com/search/?keyword=巴菲特:美元未来不一定是储备货币&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683436260},{"duration":11340,"searchNums":6937663,"keywords":"拜登政府对台提供5亿美元军援","updateTime":1683435360,"type":"kwai","topRanking":6,"url":"","firstRankingTime":1683359460},{"duration":660,"searchNums":21969,"keywords":"2023全球票房破100亿美元","updateTime":1683432660,"type":"realTimeHotSpots","topRanking":63,"url":"https://s.weibo.com/weibo?q=%232023%E5%85%A8%E7%90%83%E7%A5%A8%E6%88%BF%E7%A0%B4100%E4%BA%BF%E7%BE%8E%E5%85%83%23","firstRankingTime":1683430980},{"duration":41580,"searchNums":206584,"keywords":"中国奥委会获捐1040万美元","updateTime":1683418440,"type":"toutiao","topRanking":1,"url":"https://m.toutiao.com/search/?keyword=中国奥委会获捐1040万美元&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683376920},{"duration":28800,"searchNums":41653,"keywords":"外媒:美拟向台湾提供价值5亿美元武器","updateTime":1683416400,"type":"toutiao","topRanking":18,"url":"https://m.toutiao.com/search/?keyword=外媒:美拟向台湾提供价值5亿美元武器&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683350700},{"duration":2820,"searchNums":18464,"keywords":"4月中国游戏厂商全球吸金20亿美元","updateTime":1683368460,"type":"realTimeHotSpots","topRanking":63,"url":"https://s.weibo.com/weibo?q=%234%E6%9C%88%E4%B8%AD%E5%9B%BD%E6%B8%B8%E6%88%8F%E5%8E%82%E5%95%86%E5%85%A8%E7%90%83%E5%90%B8%E9%87%9120%E4%BA%BF%E7%BE%8E%E5%85%83%23","firstRankingTime":1683364500},{"duration":2700,"searchNums":0,"keywords":"Intel净亏损28亿美元","updateTime":1683356400,"type":"bilibili","topRanking":19,"url":"https://search.bilibili.com/all?keyword=Intel%E5%87%80%E4%BA%8F%E6%8D%9F28%E4%BA%BF%E7%BE%8E%E5%85%83&from_source=webtop_search&spm_id_from=333.851","firstRankingTime":1683353700},{"duration":2880,"searchNums":7215648,"keywords":"各国放弃美元怎么办","updateTime":1683355320,"type":"kwai","topRanking":33,"url":"","firstRankingTime":1683348540},{"duration":1440,"searchNums":295947,"keywords":"是否担心多国去美元化?白宫回应","updateTime":1683354180,"type":"toutiao","topRanking":19,"url":"https://m.toutiao.com/search/?keyword=是否担心多国去美元化?白宫回应&pd=synthesis&source=trending_list&traffic_source=","firstRankingTime":1683350160}],"total":3119} 38 | """ 39 | session = requests.Session() 40 | 41 | headers = { 42 | 'Host': 'www.ent' 43 | 'obit.cn', 44 | 'Connection': 'keep-alive', 45 | 'Accept': 'application/json, text/plain, */*', 46 | 'Content-Type': 'application/x-www-form-urlencoded', 47 | 'Content-Length': '33', 48 | # 'Referer': 'https://www.entobit.cn/hot-search/nav/home?accessToken=Cjr8dOf3BVcz6kQELQ24/SHCztOETa%2BGJuB%2BR4c2SaWErDW6BR7ZBuKo5idM1TWHQ2YHNf6GjPn6Vxb971zAPw==&bindPhone=false&isIos=&isWx=', 49 | 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36' 50 | } 51 | def request(text, num): 52 | url = 'https://www.ento' \ 53 | 'bit.cn/trending/top/getWeiboRankSearch.do' 54 | key = { 55 | 'keyword': '{0}'.format(text), 56 | 'from': '{0}'.format(num) 57 | } 58 | 59 | for _ in range(3): 60 | try: 61 | res = session.post(url, headers=headers, data=key, timeout=(20, 30)) 62 | if res.status_code == 200: 63 | if res.text == "{\"rows\":[],\"total\":23}": 64 | print("time 10000") 65 | time.sleep(10000) 66 | with open("./{0}.txt".format(text), "a") as file: 67 | file.write(res.text + '\n') 68 | return True 69 | except Exception as e: 70 | print(e) 71 | 72 | return False 73 | 74 | 75 | if __name__ == '__main__': 76 | num = 1 77 | text = 'NFT' 78 | while True: 79 | print("cur = ", num) 80 | ret = request(text, num) 81 | time.sleep(5) 82 | if ret == False: 83 | print("error: ", num) 84 | time.sleep(10) 85 | 86 | num = num + 1 87 | --------------------------------------------------------------------------------