添加网站 Google SEO

谷歌分析(ga)工具

工具地址:https://www.google.com/analytics/

在项目中的 templates 下的 base.html, login.html, register.html 加入这行 GA 代码

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-152710976-1">         
    </script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'UA-152710976-1');
    </script>

谷歌管理员工具

https://search.google.com/

打开域名解析界面->修改记录

Verification method:
Domain name provider
Failure reason:
We couldn't find your verification token in your domain's TXT records.
We found these DNS TXT records instead:
v=spf1 include:spf.qiye.aliyun.com -all
Sometimes DNS changes can take a while to appear. Please wait a few hours, then reopen 

your property in Search Console. If verification fails again, try adding a different DNS TXT record.
记录类型:TXT

主机记录: @

解析路线:默认

记录值: <Google给你的TXT值>

sitemap.xml 和 robots.txt

https://www.xml-sitemaps.com/ 生成 sitemap 并把 xml 放到网站的某个位置, 在谷歌管理员工具中配置它

    location /sitemap.xml {
        alias /home/code/sitemap.xml;
    }

    location /robots.txt {
        alias /home/code/robots.txt;
    }

robots.txt 需要 sitemap.xml, https://robots.51240.com/ 生成并放在网站的根目录下

本站爬虫脚本

使用 requests + selenium + chromedriver, 可以增加机器人账号增加网站的 SEO

# -*- coding:utf8 -*-
import time
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

if __name__ == '__main__':
    chrome_options = Options()
    # chrome_options.add_argument('--headless')
    # chrome_options.add_argument('--disable-gpu')
    driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=chrome_options)
    driver.get("https://www.waterlaw.top/users/login/?next=/")
    username_elem = driver.find_element_by_xpath("/html/body/div/div/div/div/form/ul/li[1]/input")
    username_elem.clear()
    username_elem.send_keys(input("Username: "))
    password_elem = driver.find_element_by_xpath("/html/body/div/div/div/div/form/ul/li[2]/input")
    password_elem.clear()
    password_elem.send_keys(input("Password: "))
    time.sleep(5)
    driver.find_element_by_xpath("/html/body/div/div/div/div/form/ul/li[3]/button").click()
    cookies = driver.get_cookies()
    cookie_dict = dict()
    for cookie in cookies:
        item_cookie = cookie["name"]+"="+cookie["value"]+"; "
        cookie_dict[cookie["name"]] = cookie["value"]
    with requests.Session() as s:
        for i in range(1, 100):
            res = s.get("https://www.waterlaw.top/api/v1/articles/{}".format(i), cookies=cookie_dict)
            if res.status_code == 200:
                print(res.text)
    time.sleep(100000)
    driver.close()

相关博客

https://cn.bluehost.com/blog/websites/3874.html

https://www.cifnews.com/article/54418

https://www.zzshe.com/Blog/76.html

发表评论

评论内容
 

评论列表, 共 0 条评论